Skip to content

Instantly share code, notes, and snippets.

@seraphr
Created September 26, 2013 11:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seraphr/6712752 to your computer and use it in GitHub Desktop.
Save seraphr/6712752 to your computer and use it in GitHub Desktop.
Scalaのimplicitなものをimportした時のコンパイラの挙動が謎い。 仕様確認してないけど、仕様通りなの…? CompileErrorになるコードを2.8 / 2.9 で試してもコンパイルエラーだった。
// 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
}
// 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
}
// コンパイルエラー
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