File tree Expand file tree Collapse file tree 5 files changed +22
-4
lines changed
compiler/src/dotty/tools/dotc/core Expand file tree Collapse file tree 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
955955 // of null and the value denoted by p (i.e., the value v for which v eq p). [Otherwise,] the type
956956 // denotes the set consisting of only the value denoted by p.
957957 ! 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)
958961 case tp : RefinedOrRecType => isNullable(tp.parent)
959962 case tp : AppliedType => isNullable(tp.tycon)
960963 case AndType (tp1, tp2) => isNullable(tp1) && isNullable(tp2)
Original file line number Diff line number Diff line change 2929 | must be more specific than (c1 : Null)
3030 |
3131 | 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:
1313 val c1 : Null = null
1414 val c2 : c1.type = null // error
1515 end test
16+
17+ class Bar :
18+ def me : this .type = null // error
1619end Test
Original file line number Diff line number Diff line change 5353 | must be more specific than (g1 : AnyRef)
5454 |
5555 | 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
5858 | ^^^^
5959 | Found: Null
60- | Required: (Bar .this : Test.Bar )
60+ | Required: (Baz .this : Test.Baz )
6161 | 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 )
6363 |
6464 | longer explanation available when compiling with `-explain`
Original file line number Diff line number Diff line change @@ -30,5 +30,8 @@ object Test:
3030 object Mod
3131
3232 class Bar :
33+ def me : this .type = null
34+
35+ class Baz (val x : String ) extends AnyVal :
3336 def me : this .type = null // error
3437end Test
You can’t perform that action at this time.
0 commit comments