Last active
January 31, 2017 22:48
-
-
Save janekdb/cd5b30dbb33de5fb6e766c1ba1f9eb6e to your computer and use it in GitHub Desktop.
Not importing implicitConversions does not prevent compilation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### With import, without -feature flag: Compiles: YES | |
$ cat D.scala | |
import language.implicitConversions | |
object D { | |
implicit def i2s(i: Int): String = (i - 1).toString | |
val num: String = 44 | |
def main(args: Array[String]): Unit = println(num) | |
} | |
$ rm *class | |
$ ~/lib/scala-2.11.8/bin/scalac D.scala | |
$ ~/lib/scala-2.11.8/bin/scala D | |
43 | |
### With import, with -feature flag: Compiles: YES | |
$ rm *class | |
$ ~/lib/scala-2.11.8/bin/scalac -feature D.scala | |
$ ~/lib/scala-2.11.8/bin/scala D | |
43 | |
### Without import, without -feature flag: Compiles: YES | |
$ cat D.scala | |
//import language.implicitConversions | |
object D { | |
implicit def i2s(i: Int): String = (i - 1).toString | |
val num: String = 44 | |
def main(args: Array[String]): Unit = println(num) | |
} | |
$ rm *class | |
$ ~/lib/scala-2.11.8/bin/scalac D.scala | |
warning: there was one feature warning; re-run with -feature for details | |
one warning found | |
$ ~/lib/scala-2.11.8/bin/scala D | |
43 | |
### Without import, with -feature flag: Compiles: YES | |
$ rm *class | |
$ ~/lib/scala-2.11.8/bin/scalac -feature D.scala | |
D.scala:4: warning: implicit conversion method i2s 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 Scaladoc for value scala.language.implicitConversions for a discussion | |
why the feature should be explicitly enabled. | |
implicit def i2s(i: Int): String = (i - 1).toString | |
^ | |
one warning found | |
$ ~/lib/scala-2.11.8/bin/scala D | |
43 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment