Skip to content

Commit 1f5e4a3

Browse files
committed
Allow implicit conversion Predef.any2stringadd with -migration
With -migration the implicit conversion will be used and the user will see the deprecation warning.
1 parent a2903fa commit 1f5e4a3

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -347,19 +347,21 @@ class Definitions {
347347

348348
@tu lazy val ScalaPredefModule: Symbol = {
349349
val mod = ctx.requiredModule("scala.Predef")
350-
mod.infoOrCompleter match {
351-
case completer: ModuleCompleter =>
352-
mod.info = new ModuleCompleter(completer.moduleClass) {
353-
override def complete(root: SymDenotation)(implicit ctx: Context): Unit = {
354-
super.complete(root)
355-
// Disable the implicit conversion any2stringadd we remove the `implicit` moifier.
356-
// Using it explicitly will emit the usual deprection warining.
357-
val meth = root.requiredMethod("any2stringadd")
358-
meth.resetFlag(Implicit)
350+
if (!ctx.settings.migration.value) {
351+
mod.infoOrCompleter match {
352+
case completer: ModuleCompleter =>
353+
mod.info = new ModuleCompleter(completer.moduleClass) {
354+
override def complete(root: SymDenotation)(implicit ctx: Context): Unit = {
355+
super.complete(root)
356+
// Disable the implicit conversion any2stringadd we remove the `implicit` moifier.
357+
// Using it explicitly will emit the usual deprection warining.
358+
val meth = root.requiredMethod("any2stringadd")
359+
meth.resetFlag(Implicit)
360+
}
359361
}
360-
}
361-
case _ =>
362+
case _ =>
362363
// Compiling Predef from source
364+
}
363365
}
364366
mod
365367
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class CompilationTests extends ParallelTesting {
4747
compileFilesInDir("tests/pos-special/spec-t5545", defaultOptions),
4848
compileFilesInDir("tests/pos-special/strawman-collections", defaultOptions),
4949
compileFilesInDir("tests/pos-special/isInstanceOf", allowDeepSubtypes.and("-Xfatal-warnings")),
50+
compileFile("tests/pos-special/i7137.scala", defaultOptions.and("-migration")),
5051
compileFilesInDir("tests/new", defaultOptions),
5152
compileFilesInDir("tests/pos-scala2", scala2Mode),
5253
compileFilesInDir("tests/pos", defaultOptions),

tests/pos-special/i7137.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
object App {
3+
val any: Any = 3
4+
val str: String = any + "a" // allowed with -migration
5+
val str2: String = any2stringadd(any) + "a"
6+
val str3: String = Predef.any2stringadd(any) + "a"
7+
}

0 commit comments

Comments
 (0)