Skip to content

Commit 85945b0

Browse files
committed
Make toLambda not force too much
`toLambda` would always compute the denotation of a TypeRef, which makes it problematic as a widening operator, since it might force too much. It now widens only if the corresponding symbol is a TypeMethod.
1 parent 9a545e5 commit 85945b0

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -993,10 +993,19 @@ object Types {
993993
case _ => this
994994
}
995995

996-
/** If this type is a typeref with a type lambda as alias or upper bound, widen to the lambda */
997-
final def toLambda(implicit ctx: Context): Type = widen match {
998-
case tp: TypeProxy if tp.superType.isInstanceOf[LambdaType] => tp.superType
999-
case tp => tp
996+
/** If this type is a typeref or applied type referring to a TypeMethid with a type
997+
* lambda as alias or upper bound, widen to the lambda.
998+
*/
999+
final def toLambda(implicit ctx: Context): Type = {
1000+
def isLambda(tp: Type): Boolean = tp match {
1001+
case tp: TypeRef => tp.symbol.is(TypeMethod)
1002+
case tp: AppliedType => isLambda(tp.tycon)
1003+
case _ => false
1004+
}
1005+
this match {
1006+
case tp: TypeProxy if isLambda(tp) && tp.superType.isInstanceOf[LambdaType] => tp.superType
1007+
case _ => this
1008+
}
10001009
}
10011010

10021011
/** If this type contains embedded union types, replace them by their joins.

0 commit comments

Comments
 (0)