diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 715115783480..afa7bc7d29df 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1138,11 +1138,12 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper } @inline def warnNumericWiden(tpSym: Symbol, ptSym: Symbol): Unit = if (!isPastTyper) { - if (tpSym == IntClass && ptSym == FloatClass || - tpSym == LongClass && (ptSym == FloatClass || ptSym == DoubleClass)) - context.deprecationWarning(tree.pos, NoSymbol, - s"Automatic conversion from ${tpSym.name} to ${ptSym.name} is deprecated (since 2.13.1) because it loses precision. " + - s"Write `.to${ptSym.name}` instead.".stripMargin, "2.13.1") + val isInharmonic = ( + tpSym == IntClass && ptSym == FloatClass || + tpSym == LongClass && (ptSym == FloatClass || ptSym == DoubleClass) + ) + if (isInharmonic) + context.warning(tree.pos, s"Automatic conversion from ${tpSym.name} to ${ptSym.name} is deprecated (since 2.13.1) because it loses precision. Write `.to${ptSym.name}` instead.") else if (settings.warnNumericWiden) context.warning(tree.pos, "implicit numeric widening") } diff --git a/src/library/scala/Function0.scala b/src/library/scala/Function0.scala index 8e718ab0bef3..b83f2f19bd4b 100644 --- a/src/library/scala/Function0.scala +++ b/src/library/scala/Function0.scala @@ -11,7 +11,7 @@ */ // GENERATED CODE: DO NOT EDIT. -// genprod generated these sources at: 2019-06-18T20:49:11.955Z +// genprod generated these sources at: 2020-02-01T04:13:22.795Z package scala diff --git a/test/files/neg/deprecated_widening.check b/test/files/neg/deprecated_widening.check index 7e6bcce0e09a..262de21ada6d 100644 --- a/test/files/neg/deprecated_widening.check +++ b/test/files/neg/deprecated_widening.check @@ -1,21 +1,21 @@ -deprecated_widening.scala:3: warning: Automatic conversion from Int to Float is deprecated (since 2.13.1) because it loses precision. Write `.toFloat` instead. +deprecated_widening.scala:5: warning: Automatic conversion from Int to Float is deprecated (since 2.13.1) because it loses precision. Write `.toFloat` instead. val i_f: Float = i // deprecated ^ -deprecated_widening.scala:5: warning: Automatic conversion from Long to Float is deprecated (since 2.13.1) because it loses precision. Write `.toFloat` instead. +deprecated_widening.scala:7: warning: Automatic conversion from Long to Float is deprecated (since 2.13.1) because it loses precision. Write `.toFloat` instead. val l_f: Float = l // deprecated ^ -deprecated_widening.scala:6: warning: Automatic conversion from Long to Double is deprecated (since 2.13.1) because it loses precision. Write `.toDouble` instead. +deprecated_widening.scala:8: warning: Automatic conversion from Long to Double is deprecated (since 2.13.1) because it loses precision. Write `.toDouble` instead. val l_d: Double = l // deprecated ^ -deprecated_widening.scala:10: warning: method int2float in object Int is deprecated (since 2.13.1): Implicit conversion from Int to Float is dangerous because it loses precision. Write `.toFloat` instead. +deprecated_widening.scala:12: warning: method int2float in object Int is deprecated (since 2.13.1): Implicit conversion from Int to Float is dangerous because it loses precision. Write `.toFloat` instead. implicitly[Int => Float] // deprecated ^ -deprecated_widening.scala:12: warning: method long2float in object Long is deprecated (since 2.13.1): Implicit conversion from Long to Float is dangerous because it loses precision. Write `.toFloat` instead. +deprecated_widening.scala:14: warning: method long2float in object Long is deprecated (since 2.13.1): Implicit conversion from Long to Float is dangerous because it loses precision. Write `.toFloat` instead. implicitly[Long => Float] // deprecated ^ -deprecated_widening.scala:13: warning: method long2double in object Long is deprecated (since 2.13.1): Implicit conversion from Long to Double is dangerous because it loses precision. Write `.toDouble` instead. +deprecated_widening.scala:15: warning: method long2double in object Long is deprecated (since 2.13.1): Implicit conversion from Long to Double is dangerous because it loses precision. Write `.toDouble` instead. implicitly[Long => Double] // deprecated ^ error: No warnings can be incurred under -Werror. -6 warnings found -one error found +6 warnings +1 error diff --git a/test/files/neg/deprecated_widening.flags b/test/files/neg/deprecated_widening.flags deleted file mode 100644 index c6bfaf1f64a4..000000000000 --- a/test/files/neg/deprecated_widening.flags +++ /dev/null @@ -1 +0,0 @@ --deprecation -Xfatal-warnings diff --git a/test/files/neg/deprecated_widening.scala b/test/files/neg/deprecated_widening.scala index 14da7ec25fd0..7fdd288a89ff 100644 --- a/test/files/neg/deprecated_widening.scala +++ b/test/files/neg/deprecated_widening.scala @@ -1,3 +1,5 @@ +// scalac: -deprecation -Werror +// object Test { def foo(i: Int, l: Long): Unit = { val i_f: Float = i // deprecated @@ -12,4 +14,8 @@ object Test { implicitly[Long => Float] // deprecated implicitly[Long => Double] // deprecated } + + // don't leak silent warning from float conversion + val n = 42 + def clean = n max 27 }