diff options
Diffstat (limited to 'test/files/pos')
-rw-r--r-- | test/files/pos/annotated-treecopy.check | 0 | ||||
-rw-r--r-- | test/files/pos/annotated-treecopy.flags | 1 | ||||
-rw-r--r-- | test/files/pos/annotated-treecopy/Impls_Macros_1.scala | 53 | ||||
-rw-r--r-- | test/files/pos/annotated-treecopy/Test_2.scala | 5 | ||||
-rw-r--r-- | test/files/pos/attachments-typed-ident.check | 0 | ||||
-rw-r--r-- | test/files/pos/attachments-typed-ident.flags | 1 | ||||
-rw-r--r-- | test/files/pos/attachments-typed-ident/Impls_1.scala | 17 | ||||
-rw-r--r-- | test/files/pos/attachments-typed-ident/Macros_Test_2.scala | 4 | ||||
-rw-r--r-- | test/files/pos/setter-not-implicit.flags | 1 | ||||
-rw-r--r-- | test/files/pos/setter-not-implicit.scala | 3 | ||||
-rw-r--r-- | test/files/pos/strip-tvars-for-lubbasetypes.scala | 25 | ||||
-rw-r--r-- | test/files/pos/t1672.scala | 10 | ||||
-rw-r--r-- | test/files/pos/t5390.scala | 11 | ||||
-rw-r--r-- | test/files/pos/t5877.scala | 14 | ||||
-rw-r--r-- | test/files/pos/t5877b.scala | 13 | ||||
-rw-r--r-- | test/files/pos/t6547.flags | 1 | ||||
-rw-r--r-- | test/files/pos/t6547.scala | 6 | ||||
-rw-r--r-- | test/files/pos/t6595.flags | 1 | ||||
-rw-r--r-- | test/files/pos/t6595.scala | 18 | ||||
-rw-r--r-- | test/files/pos/t6712.scala | 5 |
20 files changed, 189 insertions, 0 deletions
diff --git a/test/files/pos/annotated-treecopy.check b/test/files/pos/annotated-treecopy.check new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/files/pos/annotated-treecopy.check diff --git a/test/files/pos/annotated-treecopy.flags b/test/files/pos/annotated-treecopy.flags new file mode 100644 index 0000000000..cd66464f2f --- /dev/null +++ b/test/files/pos/annotated-treecopy.flags @@ -0,0 +1 @@ +-language:experimental.macros
\ No newline at end of file diff --git a/test/files/pos/annotated-treecopy/Impls_Macros_1.scala b/test/files/pos/annotated-treecopy/Impls_Macros_1.scala new file mode 100644 index 0000000000..d92fbca380 --- /dev/null +++ b/test/files/pos/annotated-treecopy/Impls_Macros_1.scala @@ -0,0 +1,53 @@ +import scala.language.experimental.macros +import scala.reflect.macros.Context +import collection.mutable.ListBuffer +import collection.mutable.Stack + +object Macros { + trait TypedFunction { + def tree: scala.reflect.runtime.universe.Tree + val typeIn: String + val typeOut: String + } + + def tree[T,U](f:Function1[T,U]): Function1[T,U] = macro tree_impl[T,U] + + def tree_impl[T:c.WeakTypeTag,U:c.WeakTypeTag](c: Context) + (f:c.Expr[Function1[T,U]]): c.Expr[Function1[T,U]] = { + import c.universe._ + val ttag = c.weakTypeTag[U] + f match { + case Expr(Function(List(ValDef(_,n,tp,_)),b)) => + // normalize argument name + var b1 = new Transformer { + override def transform(tree: Tree): Tree = tree match { + case Ident(x) if (x==n) => Ident(newTermName("_arg")) + case tt @ TypeTree() if tt.original != null => TypeTree(tt.tpe) setOriginal transform(tt.original) + // without the fix to LazyTreeCopier.Annotated, we would need to uncomment the line below to make the macro work + // that's because the pattern match in the input expression gets expanded into Typed(<x>, TypeTree(<Int @unchecked>)) + // with the original of the TypeTree being Annotated(<@unchecked>, Ident(<x>)) + // then the macro tries to replace all Ident(<x>) trees with Ident(<_arg>), recurs into the original of the TypeTree, changes it, + // but leaves the <@unchecked> part untouched. this signals the misguided LazyTreeCopier that the Annotated tree hasn't been modified, + // so the original tree should be copied over and returned => crash when later <x: @unchecked> re-emerges from TypeTree.original + // case Annotated(annot, arg) => treeCopy.Annotated(tree, transform(annot).duplicate, transform(arg)) + case _ => super.transform(tree) + } + }.transform(b) + + val reifiedTree = c.reifyTree(treeBuild.mkRuntimeUniverseRef, EmptyTree, b1) + val reifiedExpr = c.Expr[scala.reflect.runtime.universe.Expr[T => U]](reifiedTree) + val template = + c.universe.reify(new (T => U) with TypedFunction { + override def toString = c.literal(tp+" => "+ttag.tpe+" { "+b1.toString+" } ").splice // DEBUG + def tree = reifiedExpr.splice.tree + val typeIn = c.literal(tp.toString).splice + val typeOut = c.literal(ttag.tpe.toString).splice + def apply(_arg: T): U = c.Expr[U](b1)(ttag.asInstanceOf[c.WeakTypeTag[U]]).splice + }) + val untyped = c.resetLocalAttrs(template.tree) + + c.Expr[T => U](untyped) + case _ => sys.error("Bad function type") + } + } +}
\ No newline at end of file diff --git a/test/files/pos/annotated-treecopy/Test_2.scala b/test/files/pos/annotated-treecopy/Test_2.scala new file mode 100644 index 0000000000..836e0d888d --- /dev/null +++ b/test/files/pos/annotated-treecopy/Test_2.scala @@ -0,0 +1,5 @@ +object Test extends App { + import Macros._ + // tree { (x:((Int,Int,Int),(Int,Int,Int))) => { val y=x; val ((r1,m1,c1),(r2,m2,c2))=y; (r1, m1 + m2 + r1 * c1 * c2, c2) } } + tree { (x:((Int,Int,Int),(Int,Int,Int))) => { val ((r1,m1,c1),(r2,m2,c2))=x; (r1, m1 + m2 + r1 * c1 * c2, c2) } } +}
\ No newline at end of file diff --git a/test/files/pos/attachments-typed-ident.check b/test/files/pos/attachments-typed-ident.check new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/files/pos/attachments-typed-ident.check diff --git a/test/files/pos/attachments-typed-ident.flags b/test/files/pos/attachments-typed-ident.flags new file mode 100644 index 0000000000..cd66464f2f --- /dev/null +++ b/test/files/pos/attachments-typed-ident.flags @@ -0,0 +1 @@ +-language:experimental.macros
\ No newline at end of file diff --git a/test/files/pos/attachments-typed-ident/Impls_1.scala b/test/files/pos/attachments-typed-ident/Impls_1.scala new file mode 100644 index 0000000000..cc40893a93 --- /dev/null +++ b/test/files/pos/attachments-typed-ident/Impls_1.scala @@ -0,0 +1,17 @@ +import scala.reflect.macros.Context +import language.experimental.macros + +object MyAttachment + +object Macros { + def impl(c: Context) = { + import c.universe._ + val ident = Ident(newTermName("bar")) updateAttachment MyAttachment + assert(ident.attachments.get[MyAttachment.type].isDefined, ident.attachments) + val typed = c.typeCheck(ident) + assert(typed.attachments.get[MyAttachment.type].isDefined, typed.attachments) + c.Expr[Int](typed) + } + + def foo = macro impl +}
\ No newline at end of file diff --git a/test/files/pos/attachments-typed-ident/Macros_Test_2.scala b/test/files/pos/attachments-typed-ident/Macros_Test_2.scala new file mode 100644 index 0000000000..37065ead4b --- /dev/null +++ b/test/files/pos/attachments-typed-ident/Macros_Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + def bar = 2 + Macros.foo +}
\ No newline at end of file diff --git a/test/files/pos/setter-not-implicit.flags b/test/files/pos/setter-not-implicit.flags new file mode 100644 index 0000000000..792c40565b --- /dev/null +++ b/test/files/pos/setter-not-implicit.flags @@ -0,0 +1 @@ +-feature -Xfatal-warnings
\ No newline at end of file diff --git a/test/files/pos/setter-not-implicit.scala b/test/files/pos/setter-not-implicit.scala new file mode 100644 index 0000000000..9bfffc2ceb --- /dev/null +++ b/test/files/pos/setter-not-implicit.scala @@ -0,0 +1,3 @@ +object O { + implicit var x: Int = 0 +} diff --git a/test/files/pos/strip-tvars-for-lubbasetypes.scala b/test/files/pos/strip-tvars-for-lubbasetypes.scala new file mode 100644 index 0000000000..2be8625bae --- /dev/null +++ b/test/files/pos/strip-tvars-for-lubbasetypes.scala @@ -0,0 +1,25 @@ +object Test { + + implicit final class EqualOps[T](val x: T) extends AnyVal { + def ===[T1, Ph >: T <: T1, Ph2 >: Ph <: T1](other: T1): Boolean = x == other + def !!![T1, Ph2 >: Ph <: T1, Ph >: T <: T1](other: T1): Boolean = x == other + } + + class A + class B extends A + class C extends A + + val a = new A + val b = new B + val c = new C + + val x1 = a === b + val x2 = b === a + val x3 = b === c // error, infers Object{} for T1 + val x4 = b.===[A, B, B](c) + + val x5 = b !!! c // always compiled due to the order of Ph2 and Ph + + + +} diff --git a/test/files/pos/t1672.scala b/test/files/pos/t1672.scala new file mode 100644 index 0000000000..5ee6bb1759 --- /dev/null +++ b/test/files/pos/t1672.scala @@ -0,0 +1,10 @@ +object Test { + @annotation.tailrec + def bar : Nothing = { + try { + throw new RuntimeException + } catch { + case _: Throwable => bar + } + } +} diff --git a/test/files/pos/t5390.scala b/test/files/pos/t5390.scala new file mode 100644 index 0000000000..36febb6a58 --- /dev/null +++ b/test/files/pos/t5390.scala @@ -0,0 +1,11 @@ +class A { + case class B[A](s: String) +} + +object X { + def foo { + val a = new A + val b = new a.B[c.type]("") // not a forward reference + val c = "" + } +}
\ No newline at end of file diff --git a/test/files/pos/t5877.scala b/test/files/pos/t5877.scala new file mode 100644 index 0000000000..c7827df99f --- /dev/null +++ b/test/files/pos/t5877.scala @@ -0,0 +1,14 @@ +package foo { + class Foo + + object Test { + new Foo().huzzah + } +} + +package object foo { + // Crasher: No synthetics for method PimpedFoo2: synthetics contains + implicit class PimpedFoo2(value: Foo) { + def huzzah = "" + } +} diff --git a/test/files/pos/t5877b.scala b/test/files/pos/t5877b.scala new file mode 100644 index 0000000000..6b8cbd473e --- /dev/null +++ b/test/files/pos/t5877b.scala @@ -0,0 +1,13 @@ +package foo + +class Foo + +object Test { + new Foo().huzzah +} + +object `package` { + implicit class PimpedFoo2(value: Foo) { + def huzzah = "" + } +} diff --git a/test/files/pos/t6547.flags b/test/files/pos/t6547.flags new file mode 100644 index 0000000000..c9b68d70dc --- /dev/null +++ b/test/files/pos/t6547.flags @@ -0,0 +1 @@ +-optimise diff --git a/test/files/pos/t6547.scala b/test/files/pos/t6547.scala new file mode 100644 index 0000000000..53bd798219 --- /dev/null +++ b/test/files/pos/t6547.scala @@ -0,0 +1,6 @@ +trait ConfigurableDefault[@specialized V] { + def fillArray(arr: Array[V], v: V) = (arr: Any) match { + case x: Array[Int] => null + case x: Array[Long] => v.asInstanceOf[Long] + } +} diff --git a/test/files/pos/t6595.flags b/test/files/pos/t6595.flags new file mode 100644 index 0000000000..85d8eb2ba2 --- /dev/null +++ b/test/files/pos/t6595.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/test/files/pos/t6595.scala b/test/files/pos/t6595.scala new file mode 100644 index 0000000000..437c0bcf05 --- /dev/null +++ b/test/files/pos/t6595.scala @@ -0,0 +1,18 @@ +import scala.annotation.switch + +class Foo extends { + final val b0 = 5 +} with AnyRef { + final val b1 = 10 + + // Using the @switch annotation as a means of testing that the + // type inferred for b0 is Int(5) and not Int. Only in the former + // case can a switch be generated. + def f(p: Int) = (p: @switch) match { + case `b0` => 1 + case `b1` => 2 + case 15 => 3 + case 20 => 4 + case _ => 5 + } +} diff --git a/test/files/pos/t6712.scala b/test/files/pos/t6712.scala new file mode 100644 index 0000000000..3c96eb14fb --- /dev/null +++ b/test/files/pos/t6712.scala @@ -0,0 +1,5 @@ +class H { + object O + + def foo() { object O } +} |