diff options
author | James Iry <jamesiry@gmail.com> | 2013-02-19 15:24:37 -0800 |
---|---|---|
committer | James Iry <jamesiry@gmail.com> | 2013-02-19 15:24:37 -0800 |
commit | 83011a88d040eb5be16c2dfd9d4cc608e1f5f442 (patch) | |
tree | 66b2c2e75ca9126436f00288bdb53bdbc65db45c /test/files | |
parent | 5d6e02ee2eb1b454d88d3c3fb41d4715930caa9d (diff) | |
parent | 93976204ba533e7413b61fd103384c76d0629ce0 (diff) | |
download | scala-83011a88d040eb5be16c2dfd9d4cc608e1f5f442.tar.gz scala-83011a88d040eb5be16c2dfd9d4cc608e1f5f442.tar.bz2 scala-83011a88d040eb5be16c2dfd9d4cc608e1f5f442.zip |
Merge pull request #2118 from lrytz/annotatedRetyping
Fix typing idempotency bug with Annotated trees
Diffstat (limited to 'test/files')
-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) + } +} |