diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2014-02-15 14:43:09 +0100 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2014-02-15 14:59:35 +0100 |
commit | 5b6700fa3a6b05545aa9b2c0d0493a07897464a5 (patch) | |
tree | 1528c7708d327f8b2fe47aacf0ebbe5f911fcc96 /test/files | |
parent | 3bedb19f85e09b19567c7e77bf8ea5d2e4aeff2f (diff) | |
download | scala-5b6700fa3a6b05545aa9b2c0d0493a07897464a5.tar.gz scala-5b6700fa3a6b05545aa9b2c0d0493a07897464a5.tar.bz2 scala-5b6700fa3a6b05545aa9b2c0d0493a07897464a5.zip |
adds more tests for enclosingOwners
Makes sure that it's possible to cover sbt's use cases, and also checks
that we can distinguish vals from vars (should anyone ever need that).
Diffstat (limited to 'test/files')
6 files changed, 106 insertions, 0 deletions
diff --git a/test/files/run/macro-enclosingowner-detectvar.check b/test/files/run/macro-enclosingowner-detectvar.check new file mode 100644 index 0000000000..c8f86ec735 --- /dev/null +++ b/test/files/run/macro-enclosingowner-detectvar.check @@ -0,0 +1,16 @@ +(true,false,false,false) +(true,false,false,false) +(true,false,false,false) +(true,false,false,false) +(false,true,false,false) +(false,true,false,false) +(false,true,false,false) +(false,true,false,false) +(false,false,true,false) +(false,false,true,false) +(false,false,true,false) +(false,false,true,false) +(false,false,false,true) +(false,false,false,true) +(false,false,false,true) +(false,false,false,true) diff --git a/test/files/run/macro-enclosingowner-detectvar/Macros_1.scala b/test/files/run/macro-enclosingowner-detectvar/Macros_1.scala new file mode 100644 index 0000000000..26ed64d8c3 --- /dev/null +++ b/test/files/run/macro-enclosingowner-detectvar/Macros_1.scala @@ -0,0 +1,14 @@ +import scala.reflect.macros.whitebox._ +import scala.language.experimental.macros + +object Macros { + def impl(c: Context) = { + import c.universe._ + def detectFlags(sym: TermSymbol): String = { + (sym.isVal, sym.isVar, !sym.isVal && !sym.isVar && !sym.isLazy, sym.isLazy).toString + } + q"println(${detectFlags(c.internal.enclosingOwner.asTerm)}); 42" + } + + def foo: Int = macro impl +}
\ No newline at end of file diff --git a/test/files/run/macro-enclosingowner-detectvar/Test_2.scala b/test/files/run/macro-enclosingowner-detectvar/Test_2.scala new file mode 100644 index 0000000000..58521d9429 --- /dev/null +++ b/test/files/run/macro-enclosingowner-detectvar/Test_2.scala @@ -0,0 +1,23 @@ +object Test extends App { + val a1 = Macros.foo + val a2 = Predef.identity(Predef.identity(Macros.foo)) + val a3: Int = Macros.foo + val a4: Int = Predef.identity(Predef.identity(Macros.foo)) + + var b1 = Macros.foo + var b2 = Predef.identity(Predef.identity(Macros.foo)) + var b3: Int = Macros.foo + var b4: Int = Predef.identity(Predef.identity(Macros.foo)) + + def c1 = Macros.foo + def c2 = Predef.identity(Predef.identity(Macros.foo)) + def c3: Int = Macros.foo + def c4: Int = Predef.identity(Predef.identity(Macros.foo)) + c1; c2; c3; c4; + + lazy val d1 = Macros.foo + lazy val d2 = Predef.identity(Predef.identity(Macros.foo)) + lazy val d3: Int = Macros.foo + lazy val d4: Int = Predef.identity(Predef.identity(Macros.foo)) + d1; d2; d3; d4 +}
\ No newline at end of file diff --git a/test/files/run/macro-enclosingowner-sbt.check b/test/files/run/macro-enclosingowner-sbt.check new file mode 100644 index 0000000000..3c95698e9a --- /dev/null +++ b/test/files/run/macro-enclosingowner-sbt.check @@ -0,0 +1,16 @@ +a1 +a2 +a3 +a4 +b1 +b2 +b3 +b4 +c1 +c2 +c3 +c4 +d1 +d2 +d3 +d4 diff --git a/test/files/run/macro-enclosingowner-sbt/Macros_1.scala b/test/files/run/macro-enclosingowner-sbt/Macros_1.scala new file mode 100644 index 0000000000..a98a984861 --- /dev/null +++ b/test/files/run/macro-enclosingowner-sbt/Macros_1.scala @@ -0,0 +1,14 @@ +import scala.reflect.macros.whitebox._ +import scala.language.experimental.macros + +object Macros { + def impl(c: Context) = { + import c.universe._ + def enclosingName(sym: Symbol): String = { + sym.name.toString.stripSuffix(termNames.LOCAL_SUFFIX_STRING) + } + q"println(${enclosingName(c.internal.enclosingOwner).toString}); 42" + } + + def foo: Int = macro impl +}
\ No newline at end of file diff --git a/test/files/run/macro-enclosingowner-sbt/Test_2.scala b/test/files/run/macro-enclosingowner-sbt/Test_2.scala new file mode 100644 index 0000000000..58521d9429 --- /dev/null +++ b/test/files/run/macro-enclosingowner-sbt/Test_2.scala @@ -0,0 +1,23 @@ +object Test extends App { + val a1 = Macros.foo + val a2 = Predef.identity(Predef.identity(Macros.foo)) + val a3: Int = Macros.foo + val a4: Int = Predef.identity(Predef.identity(Macros.foo)) + + var b1 = Macros.foo + var b2 = Predef.identity(Predef.identity(Macros.foo)) + var b3: Int = Macros.foo + var b4: Int = Predef.identity(Predef.identity(Macros.foo)) + + def c1 = Macros.foo + def c2 = Predef.identity(Predef.identity(Macros.foo)) + def c3: Int = Macros.foo + def c4: Int = Predef.identity(Predef.identity(Macros.foo)) + c1; c2; c3; c4; + + lazy val d1 = Macros.foo + lazy val d2 = Predef.identity(Predef.identity(Macros.foo)) + lazy val d3: Int = Macros.foo + lazy val d4: Int = Predef.identity(Predef.identity(Macros.foo)) + d1; d2; d3; d4 +}
\ No newline at end of file |