diff --git a/compiler/src/dotty/tools/dotc/config/MigrationVersion.scala b/compiler/src/dotty/tools/dotc/config/MigrationVersion.scala index 1d99caa789d3..f77aa0b06308 100644 --- a/compiler/src/dotty/tools/dotc/config/MigrationVersion.scala +++ b/compiler/src/dotty/tools/dotc/config/MigrationVersion.scala @@ -32,6 +32,7 @@ enum MigrationVersion(val warnFrom: SourceVersion, val errorFrom: SourceVersion) case ParameterEnclosedByParenthesis extends MigrationVersion(future, future) case XmlLiteral extends MigrationVersion(future, future) case GivenSyntax extends MigrationVersion(future, never) + case ImplicitParamsWithoutUsing extends MigrationVersion(`3.7`, future) require(warnFrom.ordinal <= errorFrom.ordinal) diff --git a/compiler/src/dotty/tools/dotc/typer/Migrations.scala b/compiler/src/dotty/tools/dotc/typer/Migrations.scala index f0d1d235a19c..0c7cab87cbd9 100644 --- a/compiler/src/dotty/tools/dotc/typer/Migrations.scala +++ b/compiler/src/dotty/tools/dotc/typer/Migrations.scala @@ -126,4 +126,16 @@ trait Migrations: patch(Span(pt.args.head.span.start), "using ") end contextBoundParams + /** Report implicit parameter lists and rewrite implicit parameter list to contextual params */ + def implicitParams(tree: Tree, tp: MethodOrPoly, pt: FunProto)(using Context): Unit = + val mversion = mv.ImplicitParamsWithoutUsing + if tp.companion == ImplicitMethodType && pt.applyKind != ApplyKind.Using && pt.args.nonEmpty then + val rewriteMsg = Message.rewriteNotice("This code", mversion.patchFrom) + report.errorOrMigrationWarning( + em"Implicit parameters should be provided with a `using` clause.$rewriteMsg", + pt.args.head.srcPos, mversion) + if mversion.needsPatch then + patch(Span(pt.args.head.span.start), "using ") + end implicitParams + end Migrations diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 6e0651128e8e..8ba63dfc1e67 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -4164,6 +4164,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer def methodStr = methPart(tree).symbol.showLocated if matchingApply(wtp, pt) then migrate(contextBoundParams(tree, wtp, pt)) + migrate(implicitParams(tree, wtp, pt)) if needsTupledDual(wtp, pt) then adapt(tree, pt.tupledDual, locked) else tree else if wtp.isContextualMethod then diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 689c7a330c43..b170d4be77bb 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -83,6 +83,7 @@ class CompilationTests { compileFile("tests/rewrites/ambiguous-named-tuple-assignment.scala", defaultOptions.and("-rewrite", "-source:3.6-migration")), compileFile("tests/rewrites/i21382.scala", defaultOptions.and("-indent", "-rewrite")), compileFile("tests/rewrites/unused.scala", defaultOptions.and("-rewrite", "-Wunused:all")), + compileFile("tests/rewrites/i22440.scala", defaultOptions.and("-rewrite")) ).checkRewrites() } diff --git a/scaladoc/src/dotty/tools/scaladoc/api.scala b/scaladoc/src/dotty/tools/scaladoc/api.scala index 8ff40644fac2..a6b5dfbb6933 100644 --- a/scaladoc/src/dotty/tools/scaladoc/api.scala +++ b/scaladoc/src/dotty/tools/scaladoc/api.scala @@ -143,7 +143,7 @@ object Signature: case class LinkToType(signature: Signature, dri: DRI, kind: Kind) case class HierarchyGraph(edges: Seq[(LinkToType, LinkToType)], sealedNodes: Set[LinkToType] = Set.empty): - def vertecies: Seq[LinkToType] = edges.flatten((a, b) => Seq(a, b)).distinct + def vertecies: Seq[LinkToType] = edges.flatten(using (a, b) => Seq(a, b)).distinct def verteciesWithId: Map[LinkToType, Int] = vertecies.zipWithIndex.toMap def +(edge: (LinkToType, LinkToType)): HierarchyGraph = this ++ Seq(edge) def ++(edges: Seq[(LinkToType, LinkToType)]): HierarchyGraph = diff --git a/staging/src/scala/quoted/staging/QuoteDriver.scala b/staging/src/scala/quoted/staging/QuoteDriver.scala index 0131a56cd8aa..82e91f7d7888 100644 --- a/staging/src/scala/quoted/staging/QuoteDriver.scala +++ b/staging/src/scala/quoted/staging/QuoteDriver.scala @@ -43,7 +43,7 @@ private class QuoteDriver(appClassloader: ClassLoader) extends Driver: val compiledExpr = try - new QuoteCompiler().newRun(ctx).compileExpr(exprBuilder) + new QuoteCompiler().newRun(using ctx).compileExpr(exprBuilder) catch case ex: dotty.tools.FatalError => val enrichedMessage = s"""An unhandled exception was thrown in the staging compiler. diff --git a/tests/neg/i22440.check b/tests/neg/i22440.check new file mode 100644 index 000000000000..6c8bd29a9f28 --- /dev/null +++ b/tests/neg/i22440.check @@ -0,0 +1,5 @@ +-- Error: tests/neg/i22440.scala:4:12 ---------------------------------------------------------------------------------- +4 |val _ = foo(1) // error + | ^ + | Implicit parameters should be provided with a `using` clause. + | This code can be rewritten automatically under -rewrite -source 3.7-migration. diff --git a/tests/neg/i22440.scala b/tests/neg/i22440.scala new file mode 100644 index 000000000000..79de3b71d2ec --- /dev/null +++ b/tests/neg/i22440.scala @@ -0,0 +1,4 @@ +//> using options -source future + +def foo(implicit x: Int) = x +val _ = foo(1) // error diff --git a/tests/rewrites/i22440.check b/tests/rewrites/i22440.check new file mode 100644 index 000000000000..417fd442f9f2 --- /dev/null +++ b/tests/rewrites/i22440.check @@ -0,0 +1,5 @@ +//> using options -source 3.7-migration + +def foo(implicit x: Int) = () +val _ = foo(using 1) +val _ = foo (using 1) diff --git a/tests/rewrites/i22440.scala b/tests/rewrites/i22440.scala new file mode 100644 index 000000000000..7bbe8e44b5f7 --- /dev/null +++ b/tests/rewrites/i22440.scala @@ -0,0 +1,5 @@ +//> using options -source 3.7-migration + +def foo(implicit x: Int) = () +val _ = foo(1) +val _ = foo (1) \ No newline at end of file diff --git a/tests/warn/i22440.check b/tests/warn/i22440.check new file mode 100644 index 000000000000..7799e7eb63b5 --- /dev/null +++ b/tests/warn/i22440.check @@ -0,0 +1,5 @@ +-- Warning: tests/warn/i22440.scala:4:12 ------------------------------------------------------------------------------- +4 |val _ = foo(1) // warn + | ^ + | Implicit parameters should be provided with a `using` clause. + | This code can be rewritten automatically under -rewrite -source 3.7-migration. diff --git a/tests/warn/i22440.scala b/tests/warn/i22440.scala new file mode 100644 index 000000000000..dfe88b5e5494 --- /dev/null +++ b/tests/warn/i22440.scala @@ -0,0 +1,4 @@ +//> using options -source 3.7 + +def foo(implicit x: Int) = x +val _ = foo(1) // warn