Skip to content

Commit 8229c8b

Browse files
committed
Remove unnecessary pattern binding and add more tests
1 parent 6c2147d commit 8229c8b

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
@@ -371,7 +371,7 @@ class TypeMismatch(val found: Type, expected: Type, val inTree: Option[untpd.Tre
371371
case Some(tree) if tree != null =>
372372
val content = tree.source.content().slice(tree.srcPos.startPos.start, tree.srcPos.endPos.end).mkString
373373
val replacement = tree match
374-
case a @ Apply(fun, args) => "(" + content + ").nn"
374+
case Apply(fun, args) => "(" + content + ").nn"
375375
case _ => content + ".nn"
376376
List(
377377
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
@@ -193,6 +193,65 @@ class CodeActionTest extends DottyTest:
193193
ctxx = ctxx
194194
)
195195

196+
@Test def addNN2 =
197+
val ctxx = newContext
198+
ctxx.setSetting(ctxx.settings.YexplicitNulls, true)
199+
checkCodeAction(
200+
code =
201+
"""implicit class infixOpTest(val s1: String) extends AnyVal {
202+
| def q(s2: String): String | Null = null
203+
|}
204+
| val s: String = ???
205+
| val t: String = s q s""".stripMargin,
206+
title = "Add .nn",
207+
expected =
208+
"""implicit class infixOpTest(val s1: String) extends AnyVal {
209+
| def q(s2: String): String | Null = null
210+
|}
211+
| val s: String = ???
212+
| val t: String = (s q s).nn""".stripMargin,
213+
ctxx = ctxx
214+
)
215+
216+
@Test def addNN3 =
217+
val ctxx = newContext
218+
ctxx.setSetting(ctxx.settings.YexplicitNulls, true)
219+
checkCodeAction(
220+
code =
221+
"""implicit class infixOpTest(val s1: String) extends AnyVal {
222+
| def q(s2: String, s3: String): String | Null = null
223+
|}
224+
| val s: String = ???
225+
| val t: String = s q (s, s)""".stripMargin,
226+
title = "Add .nn",
227+
expected =
228+
"""implicit class infixOpTest(val s1: String) extends AnyVal {
229+
| def q(s2: String, s3: String): String | Null = null
230+
|}
231+
| val s: String = ???
232+
| val t: String = (s q (s, s)).nn""".stripMargin,
233+
ctxx = ctxx
234+
)
235+
236+
@Test def addNN4 =
237+
val ctxx = newContext
238+
ctxx.setSetting(ctxx.settings.YexplicitNulls, true)
239+
checkCodeAction(
240+
code =
241+
"""implicit class infixOpTest(val s1: String) extends AnyVal {
242+
| def q(s2: String, s3: String): String | Null = null
243+
|}
244+
| val s: String = ???
245+
| val t: String = s.q(s, s)""".stripMargin,
246+
title = "Add .nn",
247+
expected =
248+
"""implicit class infixOpTest(val s1: String) extends AnyVal {
249+
| def q(s2: String, s3: String): String | Null = null
250+
|}
251+
| val s: String = ???
252+
| val t: String = (s.q(s, s)).nn""".stripMargin,
253+
ctxx = ctxx
254+
)
196255
// Make sure we're not using the default reporter, which is the ConsoleReporter,
197256
// meaning they will get reported in the test run and that's it.
198257
private def newContext =

0 commit comments

Comments
 (0)