aboutsummaryrefslogtreecommitdiff
path: root/tests/pos/t2913.scala
blob: f91ed7b513182aea676e46db47e8bf62c5c0b312 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class A {
  def foo(a: Int) = 0
}

class RichA {
  def foo(a: String) = 0
  def foo(a: String, b: String) = 0
  def foo() = 0
}

object TestNoAutoTupling {
  import language.noAutoTupling // try with on and off

  implicit def AToRichA(a: A): RichA = new RichA

  val a = new A
  a.foo()
  a.foo(1)

  a.foo("")   // Without implicits, a type error regarding invalid argument types is generated at `""`. This is
                  // the same position as an argument, so the 'second try' typing with an Implicit View is tried,
                  // and AToRichA(a).foo("") is found.
                  //
                  // My reading of the spec "7.3 Views" is that `a.foo` denotes a member of `a`, so the view should
                  // not be triggered.
                  //
                  // But perhaps the implementation was changed to solve See https://lampsvn.epfl.ch/trac/scala/ticket/1756

  a.foo("a", "b") // Without implicits, a type error regarding invalid arity is generated at `foo(<error>"", "")`.
                  // Typers#tryTypedApply:3274 only checks if the error is as the same position as `foo`, `"a"`, or `"b"`.
}

// t0851 is essentially the same:
object test1 {
  case class Foo[T,T2](f : (T,T2) => String) extends (((T,T2)) => String){
    def apply(t : T) = (s:T2) => f(t,s)
    def apply(p : (T,T2)) = f(p._1,p._2)
  }
  implicit def g[T](f : (T,String) => String): test1.Foo[T,String] = Foo(f)
  def main(args : Array[String]) : Unit = {
    val f = (x:Int,s:String) => s + x
    println(f(1))
    ()
  }
}
object Main {
  def main(args : Array[String]): Unit = {
    val fn = (a : Int, str : String) => "a: " + a + ", str: " + str
    implicit def fx[T](f : (T,String) => String): T => String = (x:T) => f(x,null)
    println(fn(1))
    ()
  }
}

object TestWithAutoTupling {

  implicit def AToRichA(a: A): RichA = new RichA

  val a = new A
  a.foo()
  a.foo(1)

  a.foo("")       // Without implicits, a type error regarding invalid argument types is generated at `""`. This is
                  // the same position as an argument, so the 'second try' typing with an Implicit View is tried,
                  // and AToRichA(a).foo("") is found.
                  //
                  // My reading of the spec "7.3 Views" is that `a.foo` denotes a member of `a`, so the view should
                  // not be triggered.
                  //
                  // But perhaps the implementation was changed to solve See https://lampsvn.epfl.ch/trac/scala/ticket/1756

  a.foo("a", "b") // Without implicits, a type error regarding invalid arity is generated at `foo(<error>"", "")`.
                  // Typers#tryTypedApply:3274 only checks if the error is as the same position as `foo`, `"a"`, or `"b"`.
}