From 1baf11a2bb4ed3c816e0484238b426bc0318c27c Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sun, 12 Jan 2014 14:16:04 +0100 Subject: SI-8143 Fix bug with super-accessors / dependent types Super-accessors are generated as `DefDef`'s with `EmptyTree` as a placeholder for the RHS. This is filled in later in `Mixin` in `completeSuperAccessor`. A change in `Uncurry` (SI-6443 / 493197f), however, converted this to a `{ EmptyTree }`, which evaded the pattern match in mixin. This commit adds a special case to the dependent method treatment in Uncurry to avoid generating redundant blocks. --- .../scala/tools/nsc/transform/UnCurry.scala | 12 ++++++----- test/files/pos/t8138.scala | 24 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 test/files/pos/t8138.scala diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala index 430129aaff..e61b35a621 100644 --- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala +++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala @@ -878,11 +878,13 @@ abstract class UnCurry extends InfoTransform case Packed(param, tempVal) => (param, tempVal) }.unzip - val rhs1 = localTyper.typedPos(rhs.pos) { - // Patch the method body to refer to the temp vals - val rhsSubstituted = rhs.substituteSymbols(packedParams map (_.symbol), tempVals map (_.symbol)) - // The new method body: { val p$1 = p.asInstanceOf[]; ...; } - Block(tempVals, rhsSubstituted) + val rhs1 = if (tempVals.isEmpty) rhs else { + localTyper.typedPos(rhs.pos) { + // Patch the method body to refer to the temp vals + val rhsSubstituted = rhs.substituteSymbols(packedParams map (_.symbol), tempVals map (_.symbol)) + // The new method body: { val p$1 = p.asInstanceOf[]; ...; } + Block(tempVals, rhsSubstituted) + } } (allParams :: Nil, rhs1) diff --git a/test/files/pos/t8138.scala b/test/files/pos/t8138.scala new file mode 100644 index 0000000000..b980930955 --- /dev/null +++ b/test/files/pos/t8138.scala @@ -0,0 +1,24 @@ + +class U { + trait Transformer { + def transform(a: Tree): Tree = ??? + } + trait Tree +} + +object Test { + def m(u: U) = { + class C extends u.Transformer { + override def transform(t: u.Tree): u.Tree = { + null match { + case _ => + // crashes in GenICode: + // error: Unknown type: , [class scala.reflect.internal.Types$NoType$, class scala.reflect.internal.Types$NoType$] TypeRef? false + (y: Any) => super.transform(???) + null + } + ??? + } + } + } +} -- cgit v1.2.3