diff options
author | Martin Odersky <odersky@gmail.com> | 2015-06-19 10:25:35 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-06-19 10:28:02 +0200 |
commit | 0ec9c927941ab3155d0c5edacfe3a21c8c4b74ca (patch) | |
tree | cd5e0c1cee095ddaa595fc8291af8b62c6958e17 /src/dotty/tools/dotc/typer/Checking.scala | |
parent | 78fae1152a7b381af4639d3d66ed637eac3ca9d0 (diff) | |
download | dotty-0ec9c927941ab3155d0c5edacfe3a21c8c4b74ca.tar.gz dotty-0ec9c927941ab3155d0c5edacfe3a21c8c4b74ca.tar.bz2 dotty-0ec9c927941ab3155d0c5edacfe3a21c8c4b74ca.zip |
Fix checking whether types are instantiable.
The logic for checking aginst the self type was wrong, as demonstrated
by pos/checkInstantiable.scala.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Checking.scala')
-rw-r--r-- | src/dotty/tools/dotc/typer/Checking.scala | 7 |
1 files changed, 5 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 _ => |