File tree 1 file changed +16
-1
lines changed
compiler/src/dotty/tools/dotc/typer
1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -1672,7 +1672,22 @@ class Namer { typer: Typer =>
1672
1672
// This case applies if the closure result type contains uninstantiated
1673
1673
// type variables. In this case, constrain the closure result from below
1674
1674
// by the parameter-capture-avoiding type of the body.
1675
- typedAheadExpr(mdef.rhs, tpt.tpe).tpe
1675
+ val rhsType = typedAheadExpr(mdef.rhs, tpt.tpe).tpe
1676
+
1677
+ // The following part is important since otherwise we might instantiate
1678
+ // the closure result type with a plain functon type that refers
1679
+ // to local parameters. An example where this happens in `dependent-closures.scala`
1680
+ // If the code after `val rhsType` is commented out, this file fails pickling tests.
1681
+ // AVOIDANCE TODO: Follow up why this happens, and whether there
1682
+ // are better ways to achieve this. It would be good if we could get rid of this code.
1683
+ // It seems at least partially redundant with the nesting level checking on TypeVar
1684
+ // instantiation.
1685
+ val hygienicType = TypeOps .avoid(rhsType, termParamss.flatten)
1686
+ if (! hygienicType.isValueType || ! (hygienicType <:< tpt.tpe))
1687
+ report.error(i " return type ${tpt.tpe} of lambda cannot be made hygienic; \n " +
1688
+ i " it is not a supertype of the hygienic type $hygienicType" , mdef.srcPos)
1689
+ // println(i"lifting $rhsType over $termParamss -> $hygienicType = ${tpt.tpe}")
1690
+ // println(TypeComparer.explained { implicit ctx => hygienicType <:< tpt.tpe })
1676
1691
case _ =>
1677
1692
}
1678
1693
WildcardType
You can’t perform that action at this time.
0 commit comments