diff options
author | Martin Odersky <odersky@gmail.com> | 2016-10-31 14:46:14 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-10-31 14:46:14 +0100 |
commit | 0c3a6788ababab2ac10c3dbf76cd3c088ff0582c (patch) | |
tree | cb1e1ae1012edd6c61e898086baa61e029af1faa | |
parent | d4c26fc6072e69d3f58685e6bfec4609eb9af13c (diff) | |
download | dotty-0c3a6788ababab2ac10c3dbf76cd3c088ff0582c.tar.gz dotty-0c3a6788ababab2ac10c3dbf76cd3c088ff0582c.tar.bz2 dotty-0c3a6788ababab2ac10c3dbf76cd3c088ff0582c.zip |
Keep rhs of TypeDefs until pickling
Don't convert to a TypeTree in PostTyper, because that
loses internal positions.
-rw-r--r-- | src/dotty/tools/dotc/core/tasty/TreePickler.scala | 8 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/PostTyper.scala | 33 |
2 files changed, 21 insertions, 20 deletions
diff --git a/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/src/dotty/tools/dotc/core/tasty/TreePickler.scala index a1ac69e0d..f0d8da9df 100644 --- a/src/dotty/tools/dotc/core/tasty/TreePickler.scala +++ b/src/dotty/tools/dotc/core/tasty/TreePickler.scala @@ -49,6 +49,10 @@ class TreePickler(pickler: TastyPickler) { case None => } } + + def rhs(tdef: TypeDef)(implicit ctx: Context) = + if (tdef.symbol.isClass) tdef.rhs + else TypeTree(tdef.symbol.info).withPos(tdef.rhs.pos) private def pickleName(name: Name): Unit = writeNat(nameIndex(name).index) private def pickleName(name: TastyName): Unit = writeNat(nameIndex(name).index) @@ -332,7 +336,7 @@ class TreePickler(pickler: TastyPickler) { tree match { case tree: ValDef => pickleDef(PARAM, tree.symbol, tree.tpt) case tree: DefDef => pickleDef(PARAM, tree.symbol, tree.tpt, tree.rhs) - case tree: TypeDef => pickleDef(TYPEPARAM, tree.symbol, tree.rhs) + case tree: TypeDef => pickleDef(TYPEPARAM, tree.symbol, rhs(tree)) } } @@ -474,7 +478,7 @@ class TreePickler(pickler: TastyPickler) { } pickleDef(DEFDEF, tree.symbol, tree.tpt, tree.rhs, pickleAllParams) case tree: TypeDef => - pickleDef(TYPEDEF, tree.symbol, tree.rhs) + pickleDef(TYPEDEF, tree.symbol, rhs(tree)) case tree: Template => registerDef(tree.symbol) writeByte(TEMPLATE) diff --git a/src/dotty/tools/dotc/transform/PostTyper.scala b/src/dotty/tools/dotc/transform/PostTyper.scala index 6b9fc084e..49727e70b 100644 --- a/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/src/dotty/tools/dotc/transform/PostTyper.scala @@ -223,26 +223,23 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran case tree: TypeDef => transformMemberDef(tree) val sym = tree.symbol - val tree1 = - if (sym.isClass) { - if (sym.owner.is(Package) && - ctx.compilationUnit.source.exists && - sym != defn.SourceFileAnnot) - sym.addAnnotation(Annotation.makeSourceFile(ctx.compilationUnit.source.file.path)) + if (sym.isClass) { + // Add SourceFile annotation to top-level classes + if (sym.owner.is(Package) && + ctx.compilationUnit.source.exists && + sym != defn.SourceFileAnnot) + sym.addAnnotation(Annotation.makeSourceFile(ctx.compilationUnit.source.file.path)) - if (!sym.isAnonymousClass) // ignore anonymous class - for (parent <- sym.asClass.classInfo.classParents) { - val pclazz = parent.classSymbol - if (pclazz.is(Sealed)) pclazz.addAnnotation(Annotation.makeChild(sym)) - } + // Add Child annotation to sealed parents unless current class is anonymous + if (!sym.isAnonymousClass) // ignore anonymous class + for (parent <- sym.asClass.classInfo.classParents) { + val pclazz = parent.classSymbol + if (pclazz.is(Sealed)) pclazz.addAnnotation(Annotation.makeChild(sym)) + } - tree - } - else { - //Checking.typeChecker.traverse(tree.rhs) - cpy.TypeDef(tree)(rhs = TypeTree(tree.symbol.info)) - } - super.transform(tree1) + tree + } + super.transform(tree) case tree: MemberDef => transformMemberDef(tree) super.transform(tree) |