diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-02-21 16:27:55 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-02-21 16:27:55 -0800 |
commit | 9a2455aee4cfb09030ff2c2c0e6861326487e474 (patch) | |
tree | 32007c185ead3c10f70abe6bbb5b44f66b568c55 /test | |
parent | f62d35b0d400e4d8a68046707450e58aa6d8adca (diff) | |
parent | 26be2067a9dcc0aa44063aa94581d970427c8ad6 (diff) | |
download | scala-9a2455aee4cfb09030ff2c2c0e6861326487e474.tar.gz scala-9a2455aee4cfb09030ff2c2c0e6861326487e474.tar.bz2 scala-9a2455aee4cfb09030ff2c2c0e6861326487e474.zip |
Merge pull request #2152 from retronym/topic/annotatedRetyping-2.10.1
SI-7163 backport of annotated retyping to 2.10.1
Diffstat (limited to 'test')
-rw-r--r-- | test/files/pos/annotated-original/C_2.scala | 7 | ||||
-rw-r--r-- | test/files/pos/annotated-original/M_1.scala | 7 | ||||
-rw-r--r-- | test/files/run/annotatedRetyping.check | 6 | ||||
-rw-r--r-- | test/files/run/annotatedRetyping.scala | 62 |
4 files changed, 82 insertions, 0 deletions
diff --git a/test/files/pos/annotated-original/C_2.scala b/test/files/pos/annotated-original/C_2.scala new file mode 100644 index 0000000000..36a09ffe0c --- /dev/null +++ b/test/files/pos/annotated-original/C_2.scala @@ -0,0 +1,7 @@ +object Bug { + M.m { + def s = "" + M.m(s): @unchecked // error: macro has not been expanded. + ??? + } +} diff --git a/test/files/pos/annotated-original/M_1.scala b/test/files/pos/annotated-original/M_1.scala new file mode 100644 index 0000000000..01654e02cf --- /dev/null +++ b/test/files/pos/annotated-original/M_1.scala @@ -0,0 +1,7 @@ +import language.experimental.macros +import reflect.macros.Context + +object M { + def impl(c: Context)(a: c.Expr[Any]) = c.Expr[Any](c.resetLocalAttrs(a.tree)) + def m(a: Any) = macro impl +} diff --git a/test/files/run/annotatedRetyping.check b/test/files/run/annotatedRetyping.check new file mode 100644 index 0000000000..b296a80526 --- /dev/null +++ b/test/files/run/annotatedRetyping.check @@ -0,0 +1,6 @@ +typing List(1, 2).map(((x) => { + val another = scala.Tuple2(t.nt, t.tr): @testAnn match { + case scala.Tuple2(_, _) => 1 + }; + x +})) diff --git a/test/files/run/annotatedRetyping.scala b/test/files/run/annotatedRetyping.scala new file mode 100644 index 0000000000..cf1b0f27b5 --- /dev/null +++ b/test/files/run/annotatedRetyping.scala @@ -0,0 +1,62 @@ +import scala.tools.partest._ +import scala.tools.nsc._ + +object Test extends DirectTest { + + override def extraSettings: String = "-usejavacp" + + def code = """ + class testAnn extends annotation.Annotation + + object t { + def nt = 1 + def tr = "a" + } + + class Test { + List(1,2).map(x => { + val another = ((t.nt, t.tr): @testAnn) match { case (_, _) => 1 } + x + }) + } + """.trim + + + // point of this test: type-check the "Annotated" tree twice. first time the analyzer plugin types it, + // second time the typer. + + // bug was that typedAnnotated assigned a type to the Annotated tree. The second type check would consider + // the tree as alreadyTyped, which is not cool, the Annotated needs to be transformed into a Typed tree. + + def show() { + val global = newCompiler() + import global._ + import analyzer._ + import collection.{mutable => m} + + object analyzerPlugin extends AnalyzerPlugin { + val templates: m.Map[Symbol, (Template, Typer)] = m.Map() + override def pluginsTypeSig(tpe: Type, typer: Typer, defTree: Tree, pt: Type): Type = { + defTree match { + case impl: Template => + templates += typer.context.owner -> (impl, typer) + + case dd: DefDef if dd.symbol.isPrimaryConstructor && templates.contains(dd.symbol.owner) => + val (impl, templTyper) = templates(dd.symbol.owner) + for (stat <- impl.body.filterNot(_.isDef)) { + println("typing "+ stat) + val statsOwner = impl.symbol orElse templTyper.context.owner.newLocalDummy(impl.pos) + val tpr = analyzer.newTyper(templTyper.context.make(stat, statsOwner)) + tpr.typed(stat) + } + + case _ => + } + tpe + } + } + + addAnalyzerPlugin(analyzerPlugin) + compileString(global)(code) + } +} |