diff --git a/compiler/src/dotty/tools/dotc/typer/Migrations.scala b/compiler/src/dotty/tools/dotc/typer/Migrations.scala index 8d468fd68bba..d6b95ceb93dc 100644 --- a/compiler/src/dotty/tools/dotc/typer/Migrations.scala +++ b/compiler/src/dotty/tools/dotc/typer/Migrations.scala @@ -113,6 +113,12 @@ trait Migrations: em"""Context bounds will map to context parameters. |A `using` clause is needed to pass explicit arguments to them.$rewriteMsg""", tree.srcPos, mversion) + tree match + case Apply(ta @ TypeApply(Select(New(_), _), _), Nil) => + // Remove empty arguments for calls to new that may precede the context bound. + // They are no longer necessary. + patch(Span(ta.span.end, pt.args.head.span.start - 1), "") + case _ => () if mversion.needsPatch && pt.args.nonEmpty then patch(Span(pt.args.head.span.start), "using ") end contextBoundParams diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index dd722403723a..0c5d5764949a 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -77,6 +77,7 @@ class CompilationTests { compileFile("tests/rewrites/i17399.scala", unindentOptions.and("-rewrite")), compileFile("tests/rewrites/i20002.scala", defaultOptions.and("-indent", "-rewrite")), compileDir("tests/rewrites/annotation-named-pararamters", defaultOptions.and("-rewrite", "-source:3.6-migration")), + compileFile("tests/rewrites/i21418.scala", unindentOptions.and("-rewrite", "-source:3.5-migration")), ).checkRewrites() } diff --git a/tests/rewrites/i21418.check b/tests/rewrites/i21418.check new file mode 100644 index 000000000000..6238ff0701c0 --- /dev/null +++ b/tests/rewrites/i21418.check @@ -0,0 +1,23 @@ +trait Effect[F[_]] +class Countdown[F[_]: Effect] +class Countdown1[F[_]: Effect](howMany: Int) +class Countdown2[F[_]: Effect, F2[_]: Effect] + +def foo[F[_]: Effect]() = + "foo" + +@main def Test = { + val a = new Countdown[Option](using ???) + val b = Countdown[Option](using ???) + new Countdown[Option](using ???) + val c = Countdown[List](using ???) + new Countdown2[List, Option](using ???, ???) + Countdown2[List, Option](using ???, ???) + new Countdown1[Option](10)(using ???) + new Array[Int](10) + new scala.collection.immutable.HashSet[Int] + new scala.collection.immutable.HashSet[Int]() + new scala.collection.immutable.HashSet[Int] () + foo()(using ???) + foo() (using ???) +} diff --git a/tests/rewrites/i21418.scala b/tests/rewrites/i21418.scala new file mode 100644 index 000000000000..89d0c6eb75bc --- /dev/null +++ b/tests/rewrites/i21418.scala @@ -0,0 +1,23 @@ +trait Effect[F[_]] +class Countdown[F[_]: Effect] +class Countdown1[F[_]: Effect](howMany: Int) +class Countdown2[F[_]: Effect, F2[_]: Effect] + +def foo[F[_]: Effect]() = + "foo" + +@main def Test = { + val a = new Countdown[Option]()(???) + val b = Countdown[Option]()(???) + new Countdown[Option] ()(???) + val c = Countdown[List] () (???) + new Countdown2[List, Option] () (???, ???) + Countdown2[List, Option] () (???, ???) + new Countdown1[Option](10)(???) + new Array[Int](10) + new scala.collection.immutable.HashSet[Int] + new scala.collection.immutable.HashSet[Int]() + new scala.collection.immutable.HashSet[Int] () + foo()(???) + foo() (???) +}