From 0ec9c927941ab3155d0c5edacfe3a21c8c4b74ca Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 19 Jun 2015 10:25:35 +0200 Subject: Fix checking whether types are instantiable. The logic for checking aginst the self type was wrong, as demonstrated by pos/checkInstantiable.scala. --- src/dotty/tools/dotc/typer/Checking.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/dotty/tools/dotc/typer/Checking.scala') 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 _ => -- cgit v1.2.3