Skip to content

Commit d2fcfab

Browse files
committed
Relax the SAMType#isInstantiable check
Narrowing the type is not necessary to check for instantiability, and it prevents valid SAM types with wildcards from being used. This commit does not contain any positive testcase because SAM types with wildcards need another fix present in the next commit to work.
1 parent 83c3de7 commit d2fcfab

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3811,9 +3811,8 @@ object Types {
38113811
}
38123812
def isInstantiatable(tp: Type)(implicit ctx: Context): Boolean = zeroParamClass(tp) match {
38133813
case cinfo: ClassInfo =>
3814-
val tref = tp.narrow
3815-
val selfType = cinfo.selfType.asSeenFrom(tref, cinfo.cls)
3816-
tref <:< selfType
3814+
val selfType = cinfo.selfType.asSeenFrom(tp, cinfo.cls)
3815+
tp <:< selfType
38173816
case _ =>
38183817
false
38193818
}

tests/neg/i2732.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class B {
2+
def f = 1
3+
}
4+
5+
trait A { self: B =>
6+
def g1(x: Int): Int
7+
def g2 = g1(f)
8+
}
9+
10+
object Test {
11+
// A should not be a valid SAM type because it's not instantiable
12+
val x: A = (y: Int) => y + y // error
13+
}

0 commit comments

Comments
 (0)