What is the consequence of ignoring the scala extended function warning?

I am reading this tutorial about implicit conversion.

I entered this code into the REPL using a switch -feature

:

object Rational {
    implicit def intToRational(x: Int): Rational = new Rational(x)
}

      

And I got this warning:

<console>:9: warning: implicit conversion method intToRational should be enabled
by making the implicit value scala.language.implicitConversions visible.
This can be achieved by adding the import clause 'import scala.language.implicitConversions'
or by setting the compiler option -language:implicitConversions.
See the Scala docs for value scala.language.implicitConversions for a discussion
why the feature should be explicitly enabled.
               implicit def intToRational(x: Int): Rational = new Rational(x)

      

But the implicit conversion works fine when running this code:

scala> 12 * new Rational(1, 3)
res5: Rational = 4/1

      

So, is there a bad consequence if I don't follow the warning? (i.e. adding import option or compiler option)

+3


source to share


1 answer


  • It is possible that in some future version the code will not compile without adding an import clause. Or if you want to use -Xfatal-warnings

    .

  • For other warnings about functions (reflexive calls in particular), you can actually fix them; this does not apply to this particular warning. Read the docs as per the warning.



+3


source







All Articles