Created
September 26, 2013 11:11
-
-
Save seraphr/6712752 to your computer and use it in GitHub Desktop.
Scalaのimplicitなものをimportした時のコンパイラの挙動が謎い。
仕様確認してないけど、仕様通りなの…? CompileErrorになるコードを2.8 / 2.9 で試してもコンパイルエラーだった。
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
// Implicitを上に書くとコンパイルできる | |
object Implicits { | |
implicit val v = 10 | |
} | |
object ImplicitTest { | |
import Implicits._ | |
def main(args: Array[String]): Unit = { | |
s | |
} | |
def s(implicit a: Int): Int = a | |
} | |
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
// Implicitを下に書いても、vを参照するとコンパイルできる | |
object ImplicitTest { | |
import Implicits._ | |
def main(args: Array[String]): Unit = { | |
v | |
s | |
} | |
def s(implicit a: Int): Int = a | |
} | |
object Implicits { | |
implicit val v = 10 | |
} |
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
// コンパイルエラー | |
object ImplicitTest { | |
import Implicits._ | |
def main(args: Array[String]): Unit = { | |
s | |
} | |
def s(implicit a: Int): Int = a | |
} | |
object Implicits { | |
implicit val v = 10 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment