File tree 5 files changed +22
-4
lines changed
compiler/src/dotty/tools/dotc/core 5 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -955,6 +955,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
955
955
// of null and the value denoted by p (i.e., the value v for which v eq p). [Otherwise,] the type
956
956
// denotes the set consisting of only the value denoted by p.
957
957
! ctx.explicitNulls && isNullable(tp.underlying) && tp.isStable
958
+ case tp : ThisType =>
959
+ // Same as above; this.type is also a singleton type in spec language
960
+ ! ctx.explicitNulls && isNullable(tp.underlying)
958
961
case tp : RefinedOrRecType => isNullable(tp.parent)
959
962
case tp : AppliedType => isNullable(tp.tycon)
960
963
case AndType (tp1, tp2) => isNullable(tp1) && isNullable(tp2)
Original file line number Diff line number Diff line change 29
29
| must be more specific than (c1 : Null)
30
30
|
31
31
| longer explanation available when compiling with `-explain`
32
+ -- [E007] Type Mismatch Error: tests/explicit-nulls/neg/i17467.scala:18:24 ---------------------------------------------
33
+ 18 | def me: this.type = null // error
34
+ | ^^^^
35
+ | Found: Null
36
+ | Required: (Bar.this : Test.Bar)
37
+ | Note that implicit conversions were not tried because the result of an implicit conversion
38
+ | must be more specific than (Bar.this : Test.Bar)
39
+ |
40
+ | longer explanation available when compiling with `-explain`
Original file line number Diff line number Diff line change @@ -13,4 +13,7 @@ object Test:
13
13
val c1 : Null = null
14
14
val c2 : c1.type = null // error
15
15
end test
16
+
17
+ class Bar :
18
+ def me : this .type = null // error
16
19
end Test
Original file line number Diff line number Diff line change 53
53
| must be more specific than (g1 : AnyRef)
54
54
|
55
55
| longer explanation available when compiling with `-explain`
56
- -- [E007] Type Mismatch Error: tests/neg/i17467.scala:33 :24 ------------------------------------------------------------
57
- 33 | def me: this.type = null // error
56
+ -- [E007] Type Mismatch Error: tests/neg/i17467.scala:36 :24 ------------------------------------------------------------
57
+ 36 | def me: this.type = null // error
58
58
| ^^^^
59
59
| Found: Null
60
- | Required: (Bar .this : Test.Bar )
60
+ | Required: (Baz .this : Test.Baz )
61
61
| Note that implicit conversions were not tried because the result of an implicit conversion
62
- | must be more specific than (Bar .this : Test.Bar )
62
+ | must be more specific than (Baz .this : Test.Baz )
63
63
|
64
64
| longer explanation available when compiling with `-explain`
Original file line number Diff line number Diff line change @@ -30,5 +30,8 @@ object Test:
30
30
object Mod
31
31
32
32
class Bar :
33
+ def me : this .type = null
34
+
35
+ class Baz (val x : String ) extends AnyVal :
33
36
def me : this .type = null // error
34
37
end Test
You can’t perform that action at this time.
0 commit comments