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/files/run/annotatedRetyping.scala | |
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/files/run/annotatedRetyping.scala')
-rw-r--r-- | test/files/run/annotatedRetyping.scala | 62 |
1 files changed, 62 insertions, 0 deletions
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) + } +} |