Skip to content

Commit 8b3b5b8

Browse files
SuperCl4shtgodzik
authored andcommitted
Remove unnecessary pattern binding and add more tests
[Cherry-picked 8229c8b]
1 parent 128e6c3 commit 8b3b5b8

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ class TypeMismatch(val found: Type, expected: Type, val inTree: Option[untpd.Tre
366366
case Some(tree) if tree != null =>
367367
val content = tree.source.content().slice(tree.srcPos.startPos.start, tree.srcPos.endPos.end).mkString
368368
val replacement = tree match
369-
case a @ Apply(fun, args) => "(" + content + ").nn"
369+
case Apply(fun, args) => "(" + content + ").nn"
370370
case _ => content + ".nn"
371371
List(
372372
CodeAction(title = """Add .nn""",

compiler/test/dotty/tools/dotc/reporting/CodeActionTest.scala

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,65 @@ class CodeActionTest extends DottyTest:
179179
ctxx = ctxx
180180
)
181181

182+
@Test def addNN2 =
183+
val ctxx = newContext
184+
ctxx.setSetting(ctxx.settings.YexplicitNulls, true)
185+
checkCodeAction(
186+
code =
187+
"""implicit class infixOpTest(val s1: String) extends AnyVal {
188+
| def q(s2: String): String | Null = null
189+
|}
190+
| val s: String = ???
191+
| val t: String = s q s""".stripMargin,
192+
title = "Add .nn",
193+
expected =
194+
"""implicit class infixOpTest(val s1: String) extends AnyVal {
195+
| def q(s2: String): String | Null = null
196+
|}
197+
| val s: String = ???
198+
| val t: String = (s q s).nn""".stripMargin,
199+
ctxx = ctxx
200+
)
201+
202+
@Test def addNN3 =
203+
val ctxx = newContext
204+
ctxx.setSetting(ctxx.settings.YexplicitNulls, true)
205+
checkCodeAction(
206+
code =
207+
"""implicit class infixOpTest(val s1: String) extends AnyVal {
208+
| def q(s2: String, s3: String): String | Null = null
209+
|}
210+
| val s: String = ???
211+
| val t: String = s q (s, s)""".stripMargin,
212+
title = "Add .nn",
213+
expected =
214+
"""implicit class infixOpTest(val s1: String) extends AnyVal {
215+
| def q(s2: String, s3: String): String | Null = null
216+
|}
217+
| val s: String = ???
218+
| val t: String = (s q (s, s)).nn""".stripMargin,
219+
ctxx = ctxx
220+
)
221+
222+
@Test def addNN4 =
223+
val ctxx = newContext
224+
ctxx.setSetting(ctxx.settings.YexplicitNulls, true)
225+
checkCodeAction(
226+
code =
227+
"""implicit class infixOpTest(val s1: String) extends AnyVal {
228+
| def q(s2: String, s3: String): String | Null = null
229+
|}
230+
| val s: String = ???
231+
| val t: String = s.q(s, s)""".stripMargin,
232+
title = "Add .nn",
233+
expected =
234+
"""implicit class infixOpTest(val s1: String) extends AnyVal {
235+
| def q(s2: String, s3: String): String | Null = null
236+
|}
237+
| val s: String = ???
238+
| val t: String = (s.q(s, s)).nn""".stripMargin,
239+
ctxx = ctxx
240+
)
182241
// Make sure we're not using the default reporter, which is the ConsoleReporter,
183242
// meaning they will get reported in the test run and that's it.
184243
private def newContext =

0 commit comments

Comments
 (0)