Skip to content

Commit 5730f91

Browse files
Remove empty argument lists for classes with only context bounds (#21513)
Closes #21418
2 parents f774497 + 40c083d commit 5730f91

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

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

+6
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

+1
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

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
Countdown[Option](using ???)
12+
val b = Countdown[Option](using ???)
13+
new Countdown[Option](using ???)
14+
val c = Countdown[List](using ???)
15+
new Countdown2[List, Option](using ???, ???)
16+
new Countdown2[List, Option] (using ???, ???)
17+
Countdown2[List, Option](using ???, ???)
18+
Countdown2[List, Option] (using ???, ???)
19+
new Countdown1[Option](10)(using ???)
20+
new Array[Int](10)
21+
new scala.collection.immutable.HashSet[Int]
22+
new scala.collection.immutable.HashSet[Int]()
23+
new scala.collection.immutable.HashSet[Int] ()
24+
foo()(using ???)
25+
foo() (using ???)
26+
}

tests/rewrites/i21418.scala

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
Countdown[Option]()(???)
12+
val b = Countdown[Option]()(???)
13+
new Countdown[Option] ()(???)
14+
val c = Countdown[List] () (???)
15+
new Countdown2[List, Option] () (???, ???)
16+
new Countdown2[List, Option] (using ???, ???)
17+
Countdown2[List, Option] () (???, ???)
18+
Countdown2[List, Option] (using ???, ???)
19+
new Countdown1[Option](10)(???)
20+
new Array[Int](10)
21+
new scala.collection.immutable.HashSet[Int]
22+
new scala.collection.immutable.HashSet[Int]()
23+
new scala.collection.immutable.HashSet[Int] ()
24+
foo()(???)
25+
foo() (???)
26+
}

0 commit comments

Comments
 (0)