Skip to content

Commit ebe3785

Browse files
committed
Remove empty argument lists for classes with only context bounds
Closes #21418
1 parent 5e83606 commit ebe3785

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

compiler/src/dotty/tools/dotc/typer/Migrations.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ trait Migrations:
113113
em"""Context bounds will map to context parameters.
114114
|A `using` clause is needed to pass explicit arguments to them.$rewriteMsg""",
115115
tree.srcPos, mversion)
116+
tree match
117+
case Apply(ta @ TypeApply(Select(New(_), _), _), Nil) =>
118+
// Remove empty arguments for calls to new that may precede the context bound.
119+
// They are no longer necessary.
120+
patch(Span(ta.span.end, pt.args.head.span.start - 1), "")
121+
case _ => ()
116122
if mversion.needsPatch && pt.args.nonEmpty then
117123
patch(Span(pt.args.head.span.start), "using ")
118124
end contextBoundParams

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class CompilationTests {
7777
compileFile("tests/rewrites/i17399.scala", unindentOptions.and("-rewrite")),
7878
compileFile("tests/rewrites/i20002.scala", defaultOptions.and("-indent", "-rewrite")),
7979
compileDir("tests/rewrites/annotation-named-pararamters", defaultOptions.and("-rewrite", "-source:3.6-migration")),
80+
compileFile("tests/rewrites/i21418.scala", unindentOptions.and("-rewrite", "-source:3.5-migration")),
8081
).checkRewrites()
8182
}
8283

tests/rewrites/i21418.check

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
trait Effect[F[_]]
2+
class Countdown[F[_]: Effect]
3+
class Countdown1[F[_]: Effect](howMany: Int)
4+
class Countdown2[F[_]: Effect, F2[_]: Effect]
5+
6+
def foo[F[_]: Effect]() =
7+
"foo"
8+
9+
@main def Test = {
10+
val a = new Countdown[Option](using ???)
11+
val b = Countdown[Option](using ???)
12+
new Countdown[Option](using ???)
13+
val c = Countdown[List](using ???)
14+
new Countdown2[List, Option](using ???, ???)
15+
Countdown2[List, Option](using ???, ???)
16+
new Countdown1[Option](10)(using ???)
17+
new Array[Int](10)
18+
new scala.collection.immutable.HashSet[Int]
19+
new scala.collection.immutable.HashSet[Int]()
20+
new scala.collection.immutable.HashSet[Int] ()
21+
foo()(using ???)
22+
foo() (using ???)
23+
}

tests/rewrites/i21418.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
trait Effect[F[_]]
2+
class Countdown[F[_]: Effect]
3+
class Countdown1[F[_]: Effect](howMany: Int)
4+
class Countdown2[F[_]: Effect, F2[_]: Effect]
5+
6+
def foo[F[_]: Effect]() =
7+
"foo"
8+
9+
@main def Test = {
10+
val a = new Countdown[Option]()(???)
11+
val b = Countdown[Option]()(???)
12+
new Countdown[Option] ()(???)
13+
val c = Countdown[List] () (???)
14+
new Countdown2[List, Option] () (???, ???)
15+
Countdown2[List, Option] () (???, ???)
16+
new Countdown1[Option](10)(???)
17+
new Array[Int](10)
18+
new scala.collection.immutable.HashSet[Int]
19+
new scala.collection.immutable.HashSet[Int]()
20+
new scala.collection.immutable.HashSet[Int] ()
21+
foo()(???)
22+
foo() (???)
23+
}

0 commit comments

Comments
 (0)