diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2016-03-31 16:06:56 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2016-03-31 16:06:56 -0700 |
commit | 5654ebddb63d078f9f79dcf84fbb8489030136f6 (patch) | |
tree | d4bfc365cdf8e4993113275136f14803ceab3abd /test/files/pos | |
parent | 4fc7d5517c7152d43745960efde5042febe29422 (diff) | |
parent | 5e5ab186fe5b8cf047fd3da58da29dbc8f9fbd71 (diff) | |
download | scala-5654ebddb63d078f9f79dcf84fbb8489030136f6.tar.gz scala-5654ebddb63d078f9f79dcf84fbb8489030136f6.tar.bz2 scala-5654ebddb63d078f9f79dcf84fbb8489030136f6.zip |
Merge pull request #4971 from adriaanm/genbcode-delambdafy
Unify treatment of built-in functions and SAMs
Diffstat (limited to 'test/files/pos')
-rw-r--r-- | test/files/pos/fun_undo_eta.scala | 10 | ||||
-rw-r--r-- | test/files/pos/sammy_ctor_arg.scala | 4 | ||||
-rw-r--r-- | test/files/pos/sammy_exist.flags | 1 | ||||
-rw-r--r-- | test/files/pos/sammy_implicit.scala | 11 | ||||
-rw-r--r-- | test/files/pos/sammy_infer_argtype_subtypes.scala | 6 | ||||
-rw-r--r-- | test/files/pos/sammy_inferargs.scala | 6 | ||||
-rw-r--r-- | test/files/pos/sammy_overload.flags | 1 | ||||
-rw-r--r-- | test/files/pos/sammy_overload.scala | 27 | ||||
-rw-r--r-- | test/files/pos/sammy_override.flags | 1 | ||||
-rw-r--r-- | test/files/pos/sammy_poly.flags | 1 | ||||
-rw-r--r-- | test/files/pos/sammy_poly.scala | 13 | ||||
-rw-r--r-- | test/files/pos/sammy_scope.flags | 1 | ||||
-rw-r--r-- | test/files/pos/sammy_scope.scala | 4 | ||||
-rw-r--r-- | test/files/pos/sammy_single.flags | 1 | ||||
-rw-r--r-- | test/files/pos/sammy_twice.flags | 1 | ||||
-rw-r--r-- | test/files/pos/t8310.flags | 1 | ||||
-rw-r--r-- | test/files/pos/t8429.scala | 7 | ||||
-rw-r--r-- | test/files/pos/t9449.scala | 19 |
18 files changed, 100 insertions, 15 deletions
diff --git a/test/files/pos/fun_undo_eta.scala b/test/files/pos/fun_undo_eta.scala new file mode 100644 index 0000000000..466b0e2629 --- /dev/null +++ b/test/files/pos/fun_undo_eta.scala @@ -0,0 +1,10 @@ +class Test { + def m(i: Int) = i + + def expectWild[A](f: A) = ??? + def expectFun[A](f: A => Int) = ??? + + expectWild((i => m(i))) // manual eta expansion + expectWild(m(_)) // have to undo eta expansion with wildcard expected type + expectFun(m(_)) // have to undo eta expansion with function expected type +} diff --git a/test/files/pos/sammy_ctor_arg.scala b/test/files/pos/sammy_ctor_arg.scala new file mode 100644 index 0000000000..3c556d59f0 --- /dev/null +++ b/test/files/pos/sammy_ctor_arg.scala @@ -0,0 +1,4 @@ +trait Fun[A, B] { def apply(a: A): B } +// can't do sam expansion until the sam body def is a static method in the sam class, and not a local method in a block' +class C(f: Fun[Int, String]) +class Test extends C(s => "a")
\ No newline at end of file diff --git a/test/files/pos/sammy_exist.flags b/test/files/pos/sammy_exist.flags deleted file mode 100644 index 48fd867160..0000000000 --- a/test/files/pos/sammy_exist.flags +++ /dev/null @@ -1 +0,0 @@ --Xexperimental diff --git a/test/files/pos/sammy_implicit.scala b/test/files/pos/sammy_implicit.scala new file mode 100644 index 0000000000..ab63fc729e --- /dev/null +++ b/test/files/pos/sammy_implicit.scala @@ -0,0 +1,11 @@ +trait Fun[A, B] { def apply(a: A): B } + +abstract class SamImplicitConvert { + class Lst[T] + abstract class Str { def getBytes: Array[Int] } + def flatMap[B](f: Fun[Str, Lst[B]]): List[B] = ??? + + implicit def conv(xs: Array[Int]): Lst[Int] + + def encoded = flatMap (_.getBytes) +} diff --git a/test/files/pos/sammy_infer_argtype_subtypes.scala b/test/files/pos/sammy_infer_argtype_subtypes.scala new file mode 100644 index 0000000000..63966f879e --- /dev/null +++ b/test/files/pos/sammy_infer_argtype_subtypes.scala @@ -0,0 +1,6 @@ +trait Fun[A, B] { def apply(a: A): B } + +class SamInferResult { + def foreach[U](f: Fun[String, U]): U = ??? + def foo = foreach(println) +}
\ No newline at end of file diff --git a/test/files/pos/sammy_inferargs.scala b/test/files/pos/sammy_inferargs.scala new file mode 100644 index 0000000000..10d9b4f0dd --- /dev/null +++ b/test/files/pos/sammy_inferargs.scala @@ -0,0 +1,6 @@ +trait Proc { def apply(): Unit } +class Test { + val initCode = List[Proc]() + initCode foreach { proc => proc() } + +} diff --git a/test/files/pos/sammy_overload.flags b/test/files/pos/sammy_overload.flags deleted file mode 100644 index 48fd867160..0000000000 --- a/test/files/pos/sammy_overload.flags +++ /dev/null @@ -1 +0,0 @@ --Xexperimental diff --git a/test/files/pos/sammy_overload.scala b/test/files/pos/sammy_overload.scala index 5472248f4d..6a3c88ec55 100644 --- a/test/files/pos/sammy_overload.scala +++ b/test/files/pos/sammy_overload.scala @@ -6,4 +6,29 @@ object Test { def foo(x: String): Unit = ??? def foo(): Unit = ??? val f: Consumer[_ >: String] = foo -}
\ No newline at end of file +} + +trait A[A, B] { def apply(a: A): B } + +class ArityDisambiguate { + object O { + def m(a: A[Int, Int]) = 0 + def m(f: (Int, Int) => Int) = 1 + } + + O.m(x => x) // ok + O.m((x, y) => x) // ok +} + +class InteractionWithImplicits { + object O { + class Ev + implicit object E1 extends Ev + implicit object E2 extends Ev + def m(a: A[Int, Int])(implicit ol: E1.type) = 0 + def m(a: A[String, Int])(implicit ol: E2.type) = 1 + } + + O.m((x: Int) => 1) // ok + O.m((x: String) => 1) // ok +} diff --git a/test/files/pos/sammy_override.flags b/test/files/pos/sammy_override.flags deleted file mode 100644 index 48fd867160..0000000000 --- a/test/files/pos/sammy_override.flags +++ /dev/null @@ -1 +0,0 @@ --Xexperimental diff --git a/test/files/pos/sammy_poly.flags b/test/files/pos/sammy_poly.flags deleted file mode 100644 index 48fd867160..0000000000 --- a/test/files/pos/sammy_poly.flags +++ /dev/null @@ -1 +0,0 @@ --Xexperimental diff --git a/test/files/pos/sammy_poly.scala b/test/files/pos/sammy_poly.scala index c629be7166..ba10baea49 100644 --- a/test/files/pos/sammy_poly.scala +++ b/test/files/pos/sammy_poly.scala @@ -1,7 +1,12 @@ // test synthesizeSAMFunction where the sam type is not fully defined -class T { - trait F[T, U] { def apply(x: T): U } - // NOTE: the f(x) desugaring for now assumes the single abstract method is called 'apply' +trait F[T, R]{ def apply(x: T): R } + +class PolySammy { + (x => x + 1): F[Int, Int] + ((x: Int) => x + 1): F[Int, Int] + ((x: String) => 1): F[String, Int] + ((x: Object) => 1): F[String, Int] + def app[T, U](x: T)(f: F[T, U]): U = f(x) app(1)(x => List(x)) -}
\ No newline at end of file +} diff --git a/test/files/pos/sammy_scope.flags b/test/files/pos/sammy_scope.flags deleted file mode 100644 index 48fd867160..0000000000 --- a/test/files/pos/sammy_scope.flags +++ /dev/null @@ -1 +0,0 @@ --Xexperimental diff --git a/test/files/pos/sammy_scope.scala b/test/files/pos/sammy_scope.scala index 8f1fe7058e..9d35501a47 100644 --- a/test/files/pos/sammy_scope.scala +++ b/test/files/pos/sammy_scope.scala @@ -1,8 +1,8 @@ // test synthesizeSAMFunction: scope hygiene -abstract class SamFun[T1, R] { self => +trait SamFun[T1, R] { self => def apply(v1: T1): R // this should type check, as the apply ref is equivalent to self.apply // it shouldn't resolve to the sam's apply that's synthesized (that wouldn't type check, hence the pos test) def compose[A](g: SamFun[A, T1]): SamFun[A, R] = { x => apply(g(x)) } -}
\ No newline at end of file +} diff --git a/test/files/pos/sammy_single.flags b/test/files/pos/sammy_single.flags deleted file mode 100644 index 48fd867160..0000000000 --- a/test/files/pos/sammy_single.flags +++ /dev/null @@ -1 +0,0 @@ --Xexperimental diff --git a/test/files/pos/sammy_twice.flags b/test/files/pos/sammy_twice.flags deleted file mode 100644 index 48fd867160..0000000000 --- a/test/files/pos/sammy_twice.flags +++ /dev/null @@ -1 +0,0 @@ --Xexperimental diff --git a/test/files/pos/t8310.flags b/test/files/pos/t8310.flags deleted file mode 100644 index 48fd867160..0000000000 --- a/test/files/pos/t8310.flags +++ /dev/null @@ -1 +0,0 @@ --Xexperimental diff --git a/test/files/pos/t8429.scala b/test/files/pos/t8429.scala new file mode 100644 index 0000000000..a2d32637e1 --- /dev/null +++ b/test/files/pos/t8429.scala @@ -0,0 +1,7 @@ +trait Must { def musta(str: String, i: Int): Unit } + +object Mustare { + def takesM(m: Must) = ??? + takesM{ (a, b) => println } // ok + takesM{ case (a: String, b: Int) => println("") } // should also be accepted +} diff --git a/test/files/pos/t9449.scala b/test/files/pos/t9449.scala new file mode 100644 index 0000000000..3b86dc80a0 --- /dev/null +++ b/test/files/pos/t9449.scala @@ -0,0 +1,19 @@ +trait II { + def apply(x: Int): Int +} + +object Test { + def ii(x: Int): Int = x + def test = { + val ii1: II = x => ii(x) // works + val ii2: II = ii // works (adapting `ii` to `II`) + val ii3: II = ii _ // works (failed before the fix) + // typedTyped({ii : (() => <empty>)}) + // typedEta(ii, pt = II) + // adapt(ii, pt = (? => ?)) + // instantiatedToMethodType(ii, pt = (? => ?)) + // val ii3: II = ii _ // error: + // found : Int => Int + // required: II + } +}
\ No newline at end of file |