From e64c5610ac90d2e360bc3b1e7a5409e0a3547e67 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 29 Apr 2016 09:51:01 +0200 Subject: [PATCH 1/3] Transform annotations only if defined in current run There's no point transforming annotations that come from classfiles. It's inefficient to do so and it's also risky because it means we'd have to make sense of Scala-2 generated trees. This should avoid the error in #1222. --- .../tools/dotc/transform/TreeTransform.scala | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/dotty/tools/dotc/transform/TreeTransform.scala b/src/dotty/tools/dotc/transform/TreeTransform.scala index 67bd2f16049e..abada9ab47a8 100644 --- a/src/dotty/tools/dotc/transform/TreeTransform.scala +++ b/src/dotty/tools/dotc/transform/TreeTransform.scala @@ -185,12 +185,19 @@ object TreeTransforms { ref match { case ref: SymDenotation => - val annotTrees = ref.annotations.map(_.tree) - val annotTrees1 = annotTrees.mapConserve(annotationTransformer.macroTransform) - val annots1 = if (annotTrees eq annotTrees1) ref.annotations else annotTrees1.map(new ConcreteAnnotation(_)) + val annots1 = + if (!ref.symbol.isDefinedInCurrentRun) ref.annotations // leave annotations read from class files alone + else { + val annotTrees = ref.annotations.map(_.tree) + val annotTrees1 = annotTrees.mapConserve(annotationTransformer.macroTransform) + if (annotTrees eq annotTrees1) ref.annotations + else annotTrees1.map(new ConcreteAnnotation(_)) + } if ((info1 eq ref.info) && (annots1 eq ref.annotations)) ref else ref.copySymDenotation(info = info1, annotations = annots1) - case _ => if (info1 eq ref.info) ref else ref.derivedSingleDenotation(ref.symbol, info1) + case _ => + if (info1 eq ref.info) ref + else ref.derivedSingleDenotation(ref.symbol, info1) } } } From fb959f7f7b1938ba0d3f833b4d2713fda6b904f9 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 29 Apr 2016 10:23:16 +0200 Subject: [PATCH 2/3] Refine todo comment --- .../tools/dotc/core/unpickleScala2/Scala2Unpickler.scala | 2 +- src/dotty/tools/dotc/typer/Applications.scala | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 83d427a8f202..cceaed53d767 100644 --- a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -179,7 +179,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas val ex = new BadSignature( sm"""error reading Scala signature of $classRoot from $source: |error occurred at position $readIndex: $msg""") - if (ctx.debug || true) original.getOrElse(ex).printStackTrace() // temporarilly enable printing of original failure signature to debug failing builds + if (ctx.debug || true) original.getOrElse(ex).printStackTrace() // temporarily enable printing of original failure signature to debug failing builds throw ex } diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index d70546f9dcf0..390ecaee97e3 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -925,7 +925,9 @@ trait Applications extends Compatibility { self: Typer => /** Drop any implicit parameter section */ def stripImplicit(tp: Type): Type = tp match { case mt: ImplicitMethodType if !mt.isDependent => - mt.resultType // todo: make sure implicit method types are not dependent + mt.resultType + // todo: make sure implicit method types are not dependent? + // but check test case in /tests/pos/depmet_implicit_chaining_zw.scala case pt: PolyType => pt.derivedPolyType(pt.paramNames, pt.paramBounds, stripImplicit(pt.resultType)) case _ => From 1c7c738a148390ffb2072fc97a81646031fb49b2 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 29 Apr 2016 10:25:28 +0200 Subject: [PATCH 3/3] Ensure more things are completed As noticed by @smarter we need to ensure that classes owning derived type params are completed, so that trees get the proper symbol attachments. This triggered when I changed annotation transformers - I have no idea whether how two could be related, though. --- src/dotty/tools/dotc/ast/Desugar.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala index b6a4dc5e760d..12c1e65a6756 100644 --- a/src/dotty/tools/dotc/ast/Desugar.scala +++ b/src/dotty/tools/dotc/ast/Desugar.scala @@ -46,7 +46,11 @@ object desugar { */ override def ensureCompletions(implicit ctx: Context) = if (!(ctx.owner is Package)) - if (ctx.owner is ModuleClass) ctx.owner.linkedClass.ensureCompleted() + if (ctx.owner.isClass) { + ctx.owner.ensureCompleted() + if (ctx.owner is ModuleClass) + ctx.owner.linkedClass.ensureCompleted() + } else ensureCompletions(ctx.outer) /** Return info of original symbol, where all references to siblings of the