diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 5e7679f43e37..3d61ac0a51f3 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2993,26 +2993,28 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer } } nestedCtx.typerState.commit() - if sourceVersion.isAtLeast(future) then - lazy val (prefix, suffix) = res match { - case Block(mdef @ DefDef(_, vparams :: Nil, _, _) :: Nil, _: Closure) => - val arity = vparams.length - if (arity > 0) ("", "") else ("(() => ", "())") - case _ => - ("(() => ", ")") - } - def remedy = - if ((prefix ++ suffix).isEmpty) "simply leave out the trailing ` _`" - else s"use `$prefix$suffix` instead" - report.errorOrMigrationWarning( - em"""The syntax ` _` is no longer supported; - |you can $remedy""", - tree.srcPos, - from = future) - if sourceVersion.isMigrating then - patch(Span(tree.span.start), prefix) - patch(Span(qual.span.end, tree.span.end), suffix) - end if + + lazy val (prefix, suffix) = res match { + case Block(mdef @ DefDef(_, vparams :: Nil, _, _) :: Nil, _: Closure) => + val arity = vparams.length + if (arity > 0) ("", "") else ("(() => ", "())") + case _ => + ("(() => ", ")") + } + def remedy = + if ((prefix ++ suffix).isEmpty) "simply leave out the trailing ` _`" + else s"use `$prefix$suffix` instead" + def rewrite = Message.rewriteNotice("This construct", `3.4-migration`) + report.gradualErrorOrMigrationWarning( + em"""The syntax ` _` is no longer supported; + |you can $remedy$rewrite""", + tree.srcPos, + warnFrom = `3.4`, + errorFrom = future) + if sourceVersion.isMigrating && sourceVersion.isAtLeast(`3.4-migration`) then + patch(Span(tree.span.start), prefix) + patch(Span(qual.span.end, tree.span.end), suffix) + res } diff --git a/language-server/src/dotty/tools/languageserver/DottyLanguageServer.scala b/language-server/src/dotty/tools/languageserver/DottyLanguageServer.scala index c58b17e49559..903a5ae3b36a 100644 --- a/language-server/src/dotty/tools/languageserver/DottyLanguageServer.scala +++ b/language-server/src/dotty/tools/languageserver/DottyLanguageServer.scala @@ -792,7 +792,7 @@ object DottyLanguageServer { * not a worksheet, no mapper is necessary. Otherwise, return `toUnwrappedPosition`. */ private def positionMapperFor(sourcefile: SourceFile): Option[SourcePosition => SourcePosition] = { - if (isWorksheet(sourcefile)) Some(toUnwrappedPosition _) + if (isWorksheet(sourcefile)) Some(toUnwrappedPosition) else None } diff --git a/tests/neg/i18867-3.4.scala b/tests/neg/i18867-3.4.scala new file mode 100644 index 000000000000..c5fd2976c8b0 --- /dev/null +++ b/tests/neg/i18867-3.4.scala @@ -0,0 +1,7 @@ +//> using options -Werror + +import language.`3.4` + +def foo(x: Int) = x + +def test = foo _ // error diff --git a/tests/neg/i18867.check b/tests/neg/i18867.check new file mode 100644 index 000000000000..014e9e7bd92e --- /dev/null +++ b/tests/neg/i18867.check @@ -0,0 +1,6 @@ +-- Error: tests/neg/i18867.scala:5:15 ---------------------------------------------------------------------------------- +5 |def test = foo _ // error + | ^^^^^ + | The syntax ` _` is no longer supported; + | you can simply leave out the trailing ` _` + | This construct can be rewritten automatically under -rewrite -source 3.4-migration. diff --git a/tests/neg/i18867.scala b/tests/neg/i18867.scala new file mode 100644 index 000000000000..722347a613f5 --- /dev/null +++ b/tests/neg/i18867.scala @@ -0,0 +1,5 @@ +//> using options -Werror + +def foo(x: Int) = x + +def test = foo _ // error diff --git a/tests/patmat/dotty.scala b/tests/patmat/dotty.scala index 509c0a68b4ba..24495fe86e32 100644 --- a/tests/patmat/dotty.scala +++ b/tests/patmat/dotty.scala @@ -5,7 +5,7 @@ object IntEqualityTestTreeMaker { class Test { def isBelow(n: Int, s: String): Boolean = false - def foo(xs: List[(Int, String)]): Unit = (xs filter (isBelow _).tupled) match { + def foo(xs: List[(Int, String)]): Unit = xs.filter(isBelow.tupled) match { case Nil => case matches => } diff --git a/tests/pos/i18867-3.3.scala b/tests/pos/i18867-3.3.scala new file mode 100644 index 000000000000..4eb0ecd9b200 --- /dev/null +++ b/tests/pos/i18867-3.3.scala @@ -0,0 +1,7 @@ +//> using options -Werror + +import language.`3.3` + +def foo(x: Int) = x + +def test = foo _ diff --git a/tests/pos/i18867-3.4.scala b/tests/pos/i18867-3.4.scala new file mode 100644 index 000000000000..e2630c0cb95c --- /dev/null +++ b/tests/pos/i18867-3.4.scala @@ -0,0 +1,5 @@ +import language.`3.4` + +def foo(x: Int) = x + +def test = foo _ // warn diff --git a/tests/rewrites/rewrites3x.check b/tests/rewrites/rewrites3x.check index 0e7e0193bdd3..c83a80a59375 100644 --- a/tests/rewrites/rewrites3x.check +++ b/tests/rewrites/rewrites3x.check @@ -8,3 +8,6 @@ def test = def g = { implicit (x: Int) => x + 1 } + +def foo(x: Int) = x +def testTrailingUnderscoreEtaExpansion = foo diff --git a/tests/rewrites/rewrites3x.scala b/tests/rewrites/rewrites3x.scala index 48e2d35b0fdd..8d066bb76a91 100644 --- a/tests/rewrites/rewrites3x.scala +++ b/tests/rewrites/rewrites3x.scala @@ -7,4 +7,7 @@ def test = def g = { implicit x: Int => x + 1 -} \ No newline at end of file +} + +def foo(x: Int) = x +def testTrailingUnderscoreEtaExpansion = foo _