@@ -4,6 +4,7 @@ import dotty.tools.DottyTest
44import dotty .tools .dotc .rewrites .Rewrites
55import dotty .tools .dotc .rewrites .Rewrites .ActionPatch
66import dotty .tools .dotc .util .SourceFile
7+ import dotty .tools .dotc .core .Contexts ._
78
89import scala .annotation .tailrec
910import scala .jdk .CollectionConverters .*
@@ -149,14 +150,43 @@ class CodeActionTest extends DottyTest:
149150 afterPhase = " patternMatcher"
150151 )
151152
153+ @ Test def removeNN =
154+ val ctxx = newContext
155+ ctxx.setSetting(ctxx.settings.YexplicitNulls , true )
156+ checkCodeAction(
157+ code =
158+ """ |val s: String|Null = "foo".nn
159+ |""" .stripMargin,
160+ title = " Remove unnecessary .nn" ,
161+ expected =
162+ """ |val s: String|Null = "foo"
163+ |""" .stripMargin,
164+ ctxx = ctxx
165+ )
166+
167+
168+ @ Test def removeNN2 =
169+ val ctxx = newContext
170+ ctxx.setSetting(ctxx.settings.YexplicitNulls , true )
171+ checkCodeAction(
172+ code =
173+ """ val s: String|Null = null.nn
174+ |""" .stripMargin,
175+ title = " Remove unnecessary .nn" ,
176+ expected =
177+ """ val s: String|Null = null
178+ |""" .stripMargin,
179+ ctxx = ctxx
180+ )
181+
152182 // Make sure we're not using the default reporter, which is the ConsoleReporter,
153183 // meaning they will get reported in the test run and that's it.
154184 private def newContext =
155185 val rep = new StoreReporter (null ) with UniqueMessagePositions with HideNonSensicalMessages
156186 initialCtx.setReporter(rep).withoutColors
157187
158- private def checkCodeAction (code : String , title : String , expected : String , afterPhase : String = " typer" ) =
159- ctx = newContext
188+ private def checkCodeAction (code : String , title : String , expected : String , afterPhase : String = " typer" , ctxx : Context = newContext ) =
189+ ctx = ctxx
160190 val source = SourceFile .virtual(" test" , code).content
161191 val runCtx = checkCompile(afterPhase, code) { (_, _) => () }
162192 val diagnostics = runCtx.reporter.removeBufferedMessages
0 commit comments