Skip to content

Commit

Permalink
Fix checking whether types are instantiable.
Browse files Browse the repository at this point in the history
The logic for checking aginst the self type was wrong, as demonstrated
by pos/checkInstantiable.scala.
  • Loading branch information
odersky committed Jun 19, 2015
1 parent 78fae11 commit 0ec9c92
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 _ =>
Expand Down
5 changes: 5 additions & 0 deletions tests/pos/checkInstantiable.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// check instantiable of parameterized self type
class LS[T] { self: LS[T] => }
object Test {
new LS[Int]
}
File renamed without changes.
File renamed without changes.

0 comments on commit 0ec9c92

Please sign in to comment.