diff options
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/neg/t6231.check | 6 | ||||
-rw-r--r-- | test/files/neg/t6231.flags | 1 | ||||
-rw-r--r-- | test/files/pos/t5508-min-okay.scala | 6 | ||||
-rw-r--r-- | test/files/pos/t5508-min-okay2.scala | 4 | ||||
-rw-r--r-- | test/files/pos/t5508-min.scala | 6 | ||||
-rw-r--r-- | test/files/pos/t5508.scala | 83 | ||||
-rw-r--r-- | test/files/pos/t6231.scala (renamed from test/files/neg/t6231.scala) | 0 | ||||
-rw-r--r-- | test/files/pos/t6231b.scala | 8 | ||||
-rw-r--r-- | test/files/run/t6992.check | 3 | ||||
-rw-r--r-- | test/files/run/t6992/Macros_1.scala | 75 | ||||
-rw-r--r-- | test/files/run/t6992/Test_2.scala | 12 | ||||
-rw-r--r-- | test/files/run/t8017.flags | 1 | ||||
-rw-r--r-- | test/files/run/t8017/value-class-lambda.scala | 40 | ||||
-rw-r--r-- | test/files/run/t8017/value-class.scala | 3 | ||||
-rw-r--r-- | test/files/run/t8048a.check | 1 | ||||
-rw-r--r-- | test/files/run/t8048a/Macros_1.scala | 11 | ||||
-rw-r--r-- | test/files/run/t8048a/Test_2.scala | 4 | ||||
-rw-r--r-- | test/files/run/t8048b.check | 3 | ||||
-rw-r--r-- | test/files/run/t8048b/Macros_1.scala | 37 | ||||
-rw-r--r-- | test/files/run/t8048b/Test_2.scala | 5 |
20 files changed, 302 insertions, 7 deletions
diff --git a/test/files/neg/t6231.check b/test/files/neg/t6231.check deleted file mode 100644 index 6e107c97c7..0000000000 --- a/test/files/neg/t6231.check +++ /dev/null @@ -1,6 +0,0 @@ -t6231.scala:4: error: Implementation restriction: local trait Bug$X$1 is unable to automatically capture the -free variable value ev$1 on behalf of <$anon: Function0>. You can manually assign it to a val inside the trait, -and refer to that val in <$anon: Function0>. For more details, see SI-6231. - def qux = { () => ev } - ^ -one error found diff --git a/test/files/neg/t6231.flags b/test/files/neg/t6231.flags deleted file mode 100644 index ac96850b69..0000000000 --- a/test/files/neg/t6231.flags +++ /dev/null @@ -1 +0,0 @@ --Ydelambdafy:inline
\ No newline at end of file diff --git a/test/files/pos/t5508-min-okay.scala b/test/files/pos/t5508-min-okay.scala new file mode 100644 index 0000000000..3a38b9c5ea --- /dev/null +++ b/test/files/pos/t5508-min-okay.scala @@ -0,0 +1,6 @@ +object Test { + trait NestedTrait { // must be nested and a trait + private val _st : Int = 0 // crashes if changed to private[this] + val escape = { () => _st } + } +} diff --git a/test/files/pos/t5508-min-okay2.scala b/test/files/pos/t5508-min-okay2.scala new file mode 100644 index 0000000000..935f28609c --- /dev/null +++ b/test/files/pos/t5508-min-okay2.scala @@ -0,0 +1,4 @@ +trait TopTrait { // must be nested and a trait + private[this] val _st : Int = 0 // crashes if TopTrait is not top level + val escape = { () => _st } +} diff --git a/test/files/pos/t5508-min.scala b/test/files/pos/t5508-min.scala new file mode 100644 index 0000000000..f59d2bd6ad --- /dev/null +++ b/test/files/pos/t5508-min.scala @@ -0,0 +1,6 @@ +object Test { + trait NestedTrait { // must be nested and a trait + private[this] val _st : Int = 0 // must be private[this] + val escape = { () => _st } + } +} diff --git a/test/files/pos/t5508.scala b/test/files/pos/t5508.scala new file mode 100644 index 0000000000..2b49758045 --- /dev/null +++ b/test/files/pos/t5508.scala @@ -0,0 +1,83 @@ +package TestTestters + +trait Test1 { + private[this] var _st : Int = 0 + def close : PartialFunction[Any,Any] = { + case x : Int => + _st = identity(_st) + } +} + +object Base1 { + trait Test2 { + private[this] var _st : Int = 0 + def close : PartialFunction[Any,Any] = { + case x : Int => + _st = identity(_st) + } + } +} + +class Test3 { + private[this] var _st : Int = 0 + def close : PartialFunction[Any,Any] = { + case x : Int => + _st = 1 + } +} + +object Base2 { + class Test4 { + private[this] var _st : Int = 0 + def close : PartialFunction[Any,Any] = { + case x : Int => + _st = 1 + } + } +} + +class Base3 { + trait Test5 { + private[this] var _st : Int = 0 + def close : PartialFunction[Any,Any] = { + case x : Int => + _st = 1 + } + } +} + +object Base4 { + trait Test6 { + private[this] var _st : Int = 0 + def close : PartialFunction[Any,Any] = { + case x : Int => () + } + } +} + +object Base5 { + trait Test7 { + private[this] var _st : Int = 0 + def close = () => { + _st = 1 + } + } +} + +object Base6 { + class Test8 { + private[this] var _st : Int = 0 + def close = () => { + _st = 1 + } + } +} + +object Base7 { + trait Test9 { + var st : Int = 0 + def close = () => { + st = 1 + } + } +} diff --git a/test/files/neg/t6231.scala b/test/files/pos/t6231.scala index 1e5b4e0e1a..1e5b4e0e1a 100644 --- a/test/files/neg/t6231.scala +++ b/test/files/pos/t6231.scala diff --git a/test/files/pos/t6231b.scala b/test/files/pos/t6231b.scala new file mode 100644 index 0000000000..b4ddfe785b --- /dev/null +++ b/test/files/pos/t6231b.scala @@ -0,0 +1,8 @@ +class Test { + def f1(t: String) = { + trait T { + def xs = Nil map (_ => t) + } + () + } +} diff --git a/test/files/run/t6992.check b/test/files/run/t6992.check new file mode 100644 index 0000000000..1a0684c995 --- /dev/null +++ b/test/files/run/t6992.check @@ -0,0 +1,3 @@ +Int +42 +42 diff --git a/test/files/run/t6992/Macros_1.scala b/test/files/run/t6992/Macros_1.scala new file mode 100644 index 0000000000..25566dddbf --- /dev/null +++ b/test/files/run/t6992/Macros_1.scala @@ -0,0 +1,75 @@ +import scala.language.experimental.macros +import scala.reflect.macros.Context + +object Macros { + def foo(name: String): Any = macro foo_impl + def foo_impl(c: Context)(name: c.Expr[String]) = { + import c.universe._ + + val Literal(Constant(lit: String)) = name.tree + val anon = newTypeName(c.fresh) + + c.Expr(Block( + ClassDef( + Modifiers(Flag.FINAL), anon, Nil, Template( + Nil, noSelfType, List( + DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(pendingSuperCall), Literal(Constant(())))), + TypeDef(Modifiers(), TypeName(lit), Nil, TypeTree(typeOf[Int])) + ) + ) + ), + Apply(Select(New(Ident(anon)), nme.CONSTRUCTOR), Nil) + )) + } + + def bar(name: String): Any = macro bar_impl + def bar_impl(c: Context)(name: c.Expr[String]) = { + import c.universe._ + + val Literal(Constant(lit: String)) = name.tree + val anon = newTypeName(c.fresh) + + c.Expr(Block( + ClassDef( + Modifiers(Flag.FINAL), anon, Nil, Template( + Nil, noSelfType, List( + DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(pendingSuperCall), Literal(Constant(())))), + DefDef( + Modifiers(), TermName(lit), Nil, Nil, TypeTree(), + c.literal(42).tree + ) + ) + ) + ), + Apply(Select(New(Ident(anon)), nme.CONSTRUCTOR), Nil) + )) + } + + def baz(name: String): Any = macro baz_impl + def baz_impl(c: Context)(name: c.Expr[String]) = { + import c.universe._ + + val Literal(Constant(lit: String)) = name.tree + val anon = newTypeName(c.fresh) + val wrapper = newTypeName(c.fresh) + + c.Expr(Block( + ClassDef( + Modifiers(), anon, Nil, Template( + Nil, emptyValDef, List( + DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(pendingSuperCall), Literal(Constant(())))), + DefDef( + Modifiers(), TermName(lit), Nil, Nil, TypeTree(), + c.literal(42).tree + ) + ) + ) + ), + ClassDef( + Modifiers(Flag.FINAL), wrapper, Nil, + Template(Ident(anon) :: Nil, noSelfType, DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(pendingSuperCall), Literal(Constant(())))) :: Nil) + ), + Apply(Select(New(Ident(wrapper)), nme.CONSTRUCTOR), Nil) + )) + } +}
\ No newline at end of file diff --git a/test/files/run/t6992/Test_2.scala b/test/files/run/t6992/Test_2.scala new file mode 100644 index 0000000000..05282d6f5b --- /dev/null +++ b/test/files/run/t6992/Test_2.scala @@ -0,0 +1,12 @@ +import scala.language.reflectiveCalls + +object Test extends App { + val foo = Macros.foo("T") + println(scala.reflect.runtime.universe.weakTypeOf[foo.T].typeSymbol.typeSignature) + + val bar = Macros.bar("test") + println(bar.test) + + val baz = Macros.baz("test") + println(baz.test) +}
\ No newline at end of file diff --git a/test/files/run/t8017.flags b/test/files/run/t8017.flags new file mode 100644 index 0000000000..48b438ddf8 --- /dev/null +++ b/test/files/run/t8017.flags @@ -0,0 +1 @@ +-Ydelambdafy:method diff --git a/test/files/run/t8017/value-class-lambda.scala b/test/files/run/t8017/value-class-lambda.scala new file mode 100644 index 0000000000..370023b194 --- /dev/null +++ b/test/files/run/t8017/value-class-lambda.scala @@ -0,0 +1,40 @@ +object Test { + def testC { + val f1 = (c: C) => c.value + val f2 = (x: Int) => new C(x) + val f3 = (c1: C) => (c2: C) => (c1, c2) + val r1 = f2(2) + val r2 = f2(2) + val r3 = f3(r1)(r2) + val result = f1(r3._2) + assert(result == 2) + } + + def testD { + val f1 = (c: D) => c.value + val f2 = (x: String) => new D(x) + val f3 = (c1: D) => (c2: D) => (c1, c2) + val r1 = f2("2") + val r2 = f2("2") + val r3 = f3(r1)(r2) + val result = f1(r3._2) + assert(result == "2") + } + + def testE { + val f1 = (c: E[Int]) => c.value + val f2 = (x: Int) => new E(x) + val f3 = (c1: E[Int]) => (c2: E[Int]) => (c1, c2) + val r1 = f2(2) + val r2 = f2(2) + val r3 = f3(r1)(r2) + val result = f1(r3._2) + assert(result == 2) + } + + def main(args: Array[String]) { + testC + testD + testE + } +} diff --git a/test/files/run/t8017/value-class.scala b/test/files/run/t8017/value-class.scala new file mode 100644 index 0000000000..821239305f --- /dev/null +++ b/test/files/run/t8017/value-class.scala @@ -0,0 +1,3 @@ +class C(val value: Int) extends AnyVal +class D(val value: String) extends AnyVal +class E[A](val value: A) extends AnyVal diff --git a/test/files/run/t8048a.check b/test/files/run/t8048a.check new file mode 100644 index 0000000000..8fb9e26e84 --- /dev/null +++ b/test/files/run/t8048a.check @@ -0,0 +1 @@ +Some(2) diff --git a/test/files/run/t8048a/Macros_1.scala b/test/files/run/t8048a/Macros_1.scala new file mode 100644 index 0000000000..f48e84f1de --- /dev/null +++ b/test/files/run/t8048a/Macros_1.scala @@ -0,0 +1,11 @@ +import scala.reflect.macros.WhiteboxContext +import scala.language.experimental.macros + +object Macros { + def impl(c: WhiteboxContext) = { + import c.universe._ + q"if (true) Some(2) else None" + } + + def foo: Any = macro impl +}
\ No newline at end of file diff --git a/test/files/run/t8048a/Test_2.scala b/test/files/run/t8048a/Test_2.scala new file mode 100644 index 0000000000..4e1c8b16b0 --- /dev/null +++ b/test/files/run/t8048a/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + val x: Option[Int] = Macros.foo + println(x) +}
\ No newline at end of file diff --git a/test/files/run/t8048b.check b/test/files/run/t8048b.check new file mode 100644 index 0000000000..083edaac24 --- /dev/null +++ b/test/files/run/t8048b.check @@ -0,0 +1,3 @@ +2 +2 +2 diff --git a/test/files/run/t8048b/Macros_1.scala b/test/files/run/t8048b/Macros_1.scala new file mode 100644 index 0000000000..b113af86ea --- /dev/null +++ b/test/files/run/t8048b/Macros_1.scala @@ -0,0 +1,37 @@ +// see the following discussions to understand what's being tested here: +// * https://issues.scala-lang.org/browse/SI-6992 +// * https://issues.scala-lang.org/browse/SI-8048 +// * http://stackoverflow.com/questions/14370842/getting-a-structural-type-with-an-anonymous-classs-methods-from-a-macro +// * http://stackoverflow.com/questions/18480707/method-cannot-be-accessed-in-macro-generated-class/18485004#18485004 +// * https://groups.google.com/forum/#!topic/scala-internals/eXQt-BPm4i8 + +import scala.language.experimental.macros +import scala.reflect.macros.WhiteboxContext + +object Macros { + def impl1(c: WhiteboxContext) = { + import c.universe._ + q""" + trait Foo { def x = 2 } + new Foo {} + """ + } + def foo1: Any = macro impl1 + + def impl2(c: WhiteboxContext) = { + import c.universe._ + q""" + class Foo { def x = 2 } + new Foo + """ + } + def foo2: Any = macro impl2 + + def impl3(c: WhiteboxContext) = { + import c.universe._ + q""" + new { def x = 2 } + """ + } + def foo3: Any = macro impl3 +}
\ No newline at end of file diff --git a/test/files/run/t8048b/Test_2.scala b/test/files/run/t8048b/Test_2.scala new file mode 100644 index 0000000000..fb410dab7a --- /dev/null +++ b/test/files/run/t8048b/Test_2.scala @@ -0,0 +1,5 @@ +object Test extends App { + println(Macros.foo1.x) + println(Macros.foo2.x) + println(Macros.foo3.x) +}
\ No newline at end of file |