diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 03573d6f387c..ec65224ac93d 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -867,7 +867,7 @@ object desugar { val nu = vparamss.foldLeft(makeNew(classTypeRef)) { (nu, vparams) => val app = Apply(nu, vparams.map(refOfDef)) vparams match { - case vparam :: _ if vparam.mods.is(Given) || vparam.name.is(ContextBoundParamName) => + case vparam :: _ if vparam.mods.isOneOf(GivenOrImplicit) || vparam.name.is(ContextBoundParamName) => app.setApplyKind(ApplyKind.Using) case _ => app } 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..0e6dc27ecf7f 100644 --- a/compiler/src/dotty/tools/dotc/typer/Migrations.scala +++ b/compiler/src/dotty/tools/dotc/typer/Migrations.scala @@ -126,4 +126,19 @@ 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 + |To disable the warning, please use the following option: + | "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s" + |""", + 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/language-server/src/dotty/tools/languageserver/DottyLanguageServer.scala b/language-server/src/dotty/tools/languageserver/DottyLanguageServer.scala index e878866be81e..9821822f6d66 100644 --- a/language-server/src/dotty/tools/languageserver/DottyLanguageServer.scala +++ b/language-server/src/dotty/tools/languageserver/DottyLanguageServer.scala @@ -611,7 +611,7 @@ class DottyLanguageServer extends LanguageServer private def inProjectsSeeing(baseDriver: InteractiveDriver, definitions: List[SourceTree], symbols: List[Symbol]): List[(InteractiveDriver, Context, List[Symbol])] = { - val projects = projectsSeeing(definitions)(baseDriver.currentCtx) + val projects = projectsSeeing(definitions)(using baseDriver.currentCtx) projects.toList.map { config => val remoteDriver = drivers(config) val ctx = remoteDriver.currentCtx diff --git a/language-server/src/dotty/tools/languageserver/worksheet/WorksheetService.scala b/language-server/src/dotty/tools/languageserver/worksheet/WorksheetService.scala index 601bf7e71557..53c7a180c406 100644 --- a/language-server/src/dotty/tools/languageserver/worksheet/WorksheetService.scala +++ b/language-server/src/dotty/tools/languageserver/worksheet/WorksheetService.scala @@ -24,7 +24,7 @@ trait WorksheetService { thisServer: DottyLanguageServer => val sendMessage = (pos: SourcePosition, msg: String) => client.publishOutput(WorksheetRunOutput(params.textDocument, range(pos).get, msg)) - runWorksheet(driver, uri, sendMessage, cancelChecker)(driver.currentCtx) + runWorksheet(driver, uri, sendMessage, cancelChecker)(using driver.currentCtx) cancelChecker.checkCanceled() WorksheetRunResult(success = true) } catch { 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..699d70f343c3 --- /dev/null +++ b/tests/neg/i22440.check @@ -0,0 +1,7 @@ +-- 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. + | To disable the warning, please use the following option: + | "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s" 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/pos/i22440.scala b/tests/pos/i22440.scala new file mode 100644 index 000000000000..f72bb25d569f --- /dev/null +++ b/tests/pos/i22440.scala @@ -0,0 +1,4 @@ +//> using options "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s" + +def foo(implicit x: Int) = x +val _ = foo(1) // warn \ No newline at end of file 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..eaa357661a59 --- /dev/null +++ b/tests/warn/i22440.check @@ -0,0 +1,7 @@ +-- 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. + | To disable the warning, please use the following option: + | "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s" 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