aboutsummaryrefslogblamecommitdiff
path: root/tests/pos/implicits1.scala
blob: 8791d61e6ac0ee6b5d28379799fa15e6f261a6aa (plain) (tree)
1
2
3
4
5
6
7
8
9
10


                                           
 





                                

                  


                                         
 



                                                               
                                                               
 









                                         

              


                           
  
                    

                
 
                           
 
 
class X(val elem: Int) {
  def foo(y: String): Int = y.length + elem
}

object X {
  implicit class BarDeco(x: X) {
    def bar: String = "!"
  }
}

object Implicits {

  implicit val impl: X = new X(0)

  implicit def conv(x: Int): X = new X(x)

  class Xdecorator(x: X) extends Object {
    def foo(cond: Boolean): Int = if (cond) x.foo("abc") else 0
  }

  implicit def XDecorator(x: X): Xdecorator = new Xdecorator(x)

  val a: Object = "abc"
  val b: Any = "abc"

  def foo(x: Int)(implicit y: X): Int = {
    println(y)
    x
  }

  val y: Int = foo(1)

  val z: X = 3

  val c: Int = y.elem

  val d: Int = z.foo("abc")
  
  //import X.BarDeco

  println(z.bar)

  val e: Int = z.foo(true) 

}