Skip to content

Instantly share code, notes, and snippets.

@mmorearty
Created January 8, 2013 20:56
Show Gist options
  • Save mmorearty/4487832 to your computer and use it in GitHub Desktop.
Save mmorearty/4487832 to your computer and use it in GitHub Desktop.
I can't get the new Scala 2.10 implicit value classes to compile. Trying to compile this with "scalac TestImplicitValue.scala" fails with the errors shown below in the Comments section. If you reply, please let me know on Twitter: @mmorearty
implicit class MyRichInt(val self: Int) extends AnyVal {
def plusOne: Int = self + 1
}
object TestImplicitValue {
def main(args: Array[String]) =
println(30.plusOne)
}
@mmorearty
Copy link
Author

$ scalac -version
Scala compiler version 2.10.0 -- Copyright 2002-2012, LAMP/EPFL

@jamesward
Copy link

Hi Mike! I think this is just a scope issue. Try:

object TestImplicitValue extends App {

  implicit class MyRichInt(val self: Int) extends AnyVal {
    def plusOne: Int = self + 1
  }

  println(30.plusOne)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment