Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove empty argument lists for classes with only context bounds #21513

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Migrations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
26 changes: 26 additions & 0 deletions tests/rewrites/i21418.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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 ???)
Countdown[Option](using ???)
val b = Countdown[Option](using ???)
new Countdown[Option](using ???)
val c = Countdown[List](using ???)
new Countdown2[List, Option](using ???, ???)
new Countdown2[List, Option] (using ???, ???)
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 ???)
}
26 changes: 26 additions & 0 deletions tests/rewrites/i21418.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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]()(???)
Countdown[Option]()(???)
val b = Countdown[Option]()(???)
new Countdown[Option] ()(???)
val c = Countdown[List] () (???)
new Countdown2[List, Option] () (???, ???)
new Countdown2[List, Option] (using ???, ???)
Countdown2[List, Option] () (???, ???)
Countdown2[List, Option] (using ???, ???)
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() (???)
}
Loading