Skip to content

Commit e25f9fd

Browse files
committed
Revert "Remove now-unnecessary avoid when typing closures"
This reverts commit 629006b.
1 parent e7f5c26 commit e25f9fd

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

+16-1
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,22 @@ class Namer { typer: Typer =>
16721672
// This case applies if the closure result type contains uninstantiated
16731673
// type variables. In this case, constrain the closure result from below
16741674
// 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 })
16761691
case _ =>
16771692
}
16781693
WildcardType

0 commit comments

Comments
 (0)