Scala source implicit conversion from Int to RichInt

I understand in Scala that Int is implicitly converted to RichInt. Where in the source this happens (I was looking at the source of Scala, but I could not find it ...)

+8
scala int implicit conversion
source share
1 answer

Take a look at Predef.intWrapper(Int): RichInt

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

Please note that while looking at the source of the library, you really do not see the conversion. The best way to see it in a small snippet is to compile it (or run in REPL) using the -Xprint:typer . This will show the conversion that is inserted by the type so that the code compiles when the types do not 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 } 
+10
source share

All Articles