File tree 4 files changed +65
-4
lines changed
compiler/src/dotty/tools/dotc/typer
4 files changed +65
-4
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import parsing.JavaParsers.JavaParser
22
22
import parsing .Parsers .Parser
23
23
import Annotations .*
24
24
import Inferencing .*
25
+ import Nullables .*
25
26
import transform .ValueClasses .*
26
27
import TypeErasure .erasure
27
28
import reporting .*
@@ -781,12 +782,19 @@ class Namer { typer: Typer =>
781
782
782
783
protected def localContext (owner : Symbol ): FreshContext = ctx.fresh.setOwner(owner).setTree(original)
783
784
785
+ /** Stores the latest NotNullInfos (updated by `setNotNullInfos`) */
786
+ private var myNotNullInfos : List [NotNullInfo ] | Null = null
787
+
784
788
/** The context with which this completer was created */
785
- given creationContext : Context = ictx
789
+ given creationContext [Dummy_so_its_a_def ]: Context =
790
+ if myNotNullInfos == null then ictx else ictx.withNotNullInfos(myNotNullInfos.nn)
786
791
787
792
// make sure testing contexts are not captured by completers
788
793
assert(! ictx.reporter.isInstanceOf [ExploringReporter ])
789
794
795
+ def setNotNullInfos (infos : List [NotNullInfo ]): Unit =
796
+ myNotNullInfos = infos
797
+
790
798
protected def typeSig (sym : Symbol ): Type = original match
791
799
case original : ValDef =>
792
800
if (sym.is(Module )) moduleValSig(sym)
Original file line number Diff line number Diff line change @@ -3297,12 +3297,11 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3297
3297
mdef.getAttachment(SymOfTree ) match {
3298
3298
case Some (sym) => sym.infoOrCompleter match {
3299
3299
case completer : Namer # Completer =>
3300
- if ( completer.creationContext.notNullInfos ne ctx.notNullInfos)
3300
+ if completer.creationContext.notNullInfos ne ctx.notNullInfos then
3301
3301
// The RHS of a val def should know about not null facts established
3302
3302
// in preceding statements (unless the DefTree is completed ahead of time,
3303
3303
// then it is impossible).
3304
- sym.info = Completer (completer.original)(
3305
- completer.creationContext.withNotNullInfos(ctx.notNullInfos))
3304
+ completer.setNotNullInfos(ctx.notNullInfos)
3306
3305
true
3307
3306
case _ =>
3308
3307
// If it has been completed, then it must be because there is a forward reference
Original file line number Diff line number Diff line change
1
+ class Test {
2
+ def test1 (s : String | Null ): Unit = {
3
+ if s == null then return
4
+
5
+ case class XXX ()
6
+ }
7
+
8
+ def test2 (s : String | Null ): Unit = {
9
+ if s == " " then return
10
+
11
+ case class XXX ()
12
+ }
13
+
14
+ def test3 (s : String | Null ): Unit = {
15
+ if s == null then return
16
+
17
+ case class XXX ()
18
+ ()
19
+ }
20
+
21
+ def test4 (s : String | Null ): String | Null = {
22
+ if s == null then return " "
23
+
24
+ case class XXX ()
25
+ " xxx"
26
+ }
27
+ }
Original file line number Diff line number Diff line change
1
+ class Test {
2
+ def test1 (s : String ): Unit = {
3
+ if s == null then return
4
+
5
+ case class XXX ()
6
+ }
7
+
8
+ def test2 (s : String ): Unit = {
9
+ if s == " " then return
10
+
11
+ case class XXX ()
12
+ }
13
+
14
+ def test3 (s : String ): Unit = {
15
+ if s == null then return
16
+
17
+ case class XXX ()
18
+ ()
19
+ }
20
+
21
+ def test4 (s : String ): String = {
22
+ if s == null then return " "
23
+
24
+ case class XXX ()
25
+ " xxx"
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments