Regards,Grzegorz Balcerek
The mechanism is less than entirely satisfactory, but here you go.
// this is a source file, don't imagine it'll work in the repl
import Predef.{ intWrapper => _ }
object Test {
def main(args: Array[String]): Unit = {
200.toHexString
}
}
See some comments at
Yeah, that's how it's supposed to work. I was just demonstrating that
you can mask it. You still have to import Predef, like this.
import Predef.{ intWrapper => _, _ }
...but I see that then the masking doesn't work, so yes, it appears to
be bug stricken.
I take it back. I was fooled because masking intWrapper allowed
longWrapper to pop up and do the conversion. But now we get the
expected behavior:
import Predef.{ intWrapper => _, longWrapper => _, _ }
object Test {
def main(args: Array[String]): Unit = {
200.toHexString
println(5)
}
}
a.scala:6: error: value toHexString is not a member of Int
200.toHexString
^
one error found
I don't get it. Why is the following program working?
$ type Test1.scala
import Predef._
import Predef.{intWrapper => _,longWrapper => _,_}
object Test1 extends Application { println(200.toHexString) }
$ scalac Test1.scala
$ scala Test1
c8
When I comment out the first line it is not compiling any more.
$ type Test1.scala
//import Predef._
import Predef.{intWrapper => _,longWrapper => _,_}
object Test1 extends Application { println(200.toHexString) }
$ scalac Test1.scala
Test1.scala:3: error: value toHexString is not a member of Int
object Test1 extends Application { println(200.toHexString) }
^
one error found
$
Why does the first line make any difference? Aren't Predef members supposed
to be implicitly imported? Isn't the first line is just redoing what is
implicitly done anyway?
Regards,
Grzegorz Balcerek
As discussed in the ticket, you can only mask predef imports from the
first line.
I did mention it was less than entirely satisfactory.
Thanks for explaining!
Grzegorz Balcerek
In your scope write:
Object Donotuseme
implicit def intWrapper(x : Int) = Donotuseme
That will shadow the implicit and hide it behind a useless one.
You should check the rules again in the sls. If this does not work in all scenarios it is a violation of the spec. I'll file another bug.
Implicits pulled from the local scope must be accessible by name with no prefix. We are shadowing the predef._ implicit here and nullifyng it. It works great for non predef imported implicits. I suggest you try this to see what the correct behavior should be.
There's a minor bug where you *have* to shadow an implicit with an implicit to remove it from the potential lookup.
On Feb 19, 2011 7:17 AM, "Jim Balter" <J...@balter.name> wrote:
By that reasoning there could only be one implicit that provides methods for a given type, but there can be any number of them -- e.g., Predef.scala defines quite a few. The compiler looks for an implicit that provides the invoked method -- toHexString here. Since no such method is defined for Donotuseme, it isn't relevant to that search:
scala> object foo {
| object Donotuseme
| implicit def intWrapper(x : Int) = Dono...
| val h = 3.toHexString
| }
defined module foo
scala> foo.h
res14: String = 3
-- Jim
On Sat, Feb 19, 2011 at 3:29 AM, Josh Suereth <joshua....@gmail.com> wrote:
>
> In your scope...