Skip to content

Commit f03f5b0

Browse files
committed
Merge pull request #668 from lampepfl/fix/#650-self-types
Fix checking whether types are instantiable.
2 parents 478be16 + 0ec9c92 commit f03f5b0

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ object Checking {
5050
if (cls.is(AbstractOrTrait))
5151
ctx.error(d"$cls is abstract; cannot be instantiated", pos)
5252
if (!cls.is(Module)) {
53-
val selfType = tp.givenSelfType.asSeenFrom(tref.prefix, cls.owner)
54-
if (selfType.exists && !(tp <:< selfType))
53+
// Create a synthetic singleton type instance, and check whether
54+
// it conforms to the self type of the class as seen from that instance.
55+
val stp = SkolemType(tp)
56+
val selfType = tref.givenSelfType.asSeenFrom(stp, cls)
57+
if (selfType.exists && !(stp <:< selfType))
5558
ctx.error(d"$tp does not conform to its self type $selfType; cannot be instantiated")
5659
}
5760
case _ =>

tests/pos/checkInstantiable.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// check instantiable of parameterized self type
2+
class LS[T] { self: LS[T] => }
3+
object Test {
4+
new LS[Int]
5+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)