Skip to content

Commit 0ddb47a

Browse files
committed
Surivive bad selftypes
These are sometimes detected after they are computed. Need to avoid a crash in AndType due to an operand that is not a value type.
1 parent ee080c6 commit 0ddb47a

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3477,7 +3477,7 @@ object Types {
34773477
if (selfTypeCache == null)
34783478
selfTypeCache = {
34793479
val given = cls.givenSelfType
3480-
if (!given.exists) appliedRef
3480+
if (!given.isValueType) appliedRef
34813481
else if (cls is Module) given
34823482
else if (ctx.erasedTypes) appliedRef
34833483
else AndType(given, appliedRef)

tests/neg/bad-selftype.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
trait x0[T] { self: x0 => } // error
2+
3+
trait x1[T] { self: (=> String) => } // error
4+
5+
trait x2[T] { self: ([X] => X) => } // error
6+

tests/neg/parser-stability-17.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
trait x0[] { x0: x0 => }
2+
class x0[x1] extends x0[x0 x0] x2 x0

0 commit comments

Comments
 (0)