diff options
-rw-r--r-- | src/dotty/tools/dotc/typer/Checking.scala | 7 | ||||
-rw-r--r-- | tests/pos/checkInstantiable.scala | 5 | ||||
-rw-r--r-- | tests/run/collections.check (renamed from tests/pending/run/collections.check) | 0 | ||||
-rw-r--r-- | tests/run/collections.scala (renamed from tests/pending/run/collections.scala) | 0 |
4 files changed, 10 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/typer/Checking.scala b/src/dotty/tools/dotc/typer/Checking.scala index b2d368e8c..0071d548f 100644 --- a/src/dotty/tools/dotc/typer/Checking.scala +++ b/src/dotty/tools/dotc/typer/Checking.scala @@ -49,8 +49,11 @@ object Checking { if (cls.is(AbstractOrTrait)) ctx.error(d"$cls is abstract; cannot be instantiated", pos) if (!cls.is(Module)) { - val selfType = tp.givenSelfType.asSeenFrom(tref.prefix, cls.owner) - if (selfType.exists && !(tp <:< selfType)) + // Create a synthetic singleton type instance, and check whether + // it conforms to the self type of the class as seen from that instance. + val stp = SkolemType(tp) + val selfType = tref.givenSelfType.asSeenFrom(stp, cls) + if (selfType.exists && !(stp <:< selfType)) ctx.error(d"$tp does not conform to its self type $selfType; cannot be instantiated") } case _ => diff --git a/tests/pos/checkInstantiable.scala b/tests/pos/checkInstantiable.scala new file mode 100644 index 000000000..c8b166b1e --- /dev/null +++ b/tests/pos/checkInstantiable.scala @@ -0,0 +1,5 @@ +// check instantiable of parameterized self type +class LS[T] { self: LS[T] => } +object Test { + new LS[Int] +} diff --git a/tests/pending/run/collections.check b/tests/run/collections.check index c24150b24..c24150b24 100644 --- a/tests/pending/run/collections.check +++ b/tests/run/collections.check diff --git a/tests/pending/run/collections.scala b/tests/run/collections.scala index acc2d93ff..acc2d93ff 100644 --- a/tests/pending/run/collections.scala +++ b/tests/run/collections.scala |