Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scala source implicit conversion from Int to RichInt

I understand in Scala that Int is implicitly converted to RichInt. Where in the source does that occur (I was browsing the Scala source, but I couldn't find it...)

like image 981
Jeff Storey Avatar asked Oct 06 '11 01:10

Jeff Storey


1 Answers

Look at Predef.intWrapper(Int): RichInt

This is inherited by Predef from LowPriorityImplicits. Inherited implicits have lower priorities than non inherited ones.

Note that by browsing library source you don't really get to see the conversion. The best way to see it on small snippet is to compile it (or run it in the REPL) with the -Xprint:typer option. This will show the conversion that is inserted by the typer to make the code compile when the types don't match:

$ scala -Xprint:typer

scala> 3.abs
[[syntax trees at end of typer]]// Scala source: <console>
// stuff removed
        private[this] val res0: Int = scala.this.Predef.intWrapper(3).abs;
// more stuff removed
}
like image 192
huynhjl Avatar answered Sep 28 '22 00:09

huynhjl