diff options
author | Martin Odersky <odersky@gmail.com> | 2015-06-19 15:35:38 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-06-19 15:35:38 +0200 |
commit | bbc584f0ac3586ce4e4a92e58f74ad69a15f0ed5 (patch) | |
tree | b02ec85a4290b94a1d92fd728af83f2e71357950 | |
parent | 1b31f068a1a01619ba2ee2635d5f3c90162bf1d1 (diff) | |
download | dotty-bbc584f0ac3586ce4e4a92e58f74ad69a15f0ed5.tar.gz dotty-bbc584f0ac3586ce4e4a92e58f74ad69a15f0ed5.tar.bz2 dotty-bbc584f0ac3586ce4e4a92e58f74ad69a15f0ed5.zip |
Fix problem with explicit outer accessors
Even if an explicit outer accessor was a method, it got a TermRef as type.
-rw-r--r-- | src/dotty/tools/dotc/transform/ExplicitOuter.scala | 6 | ||||
-rw-r--r-- | tests/run/i659.scala | 12 |
2 files changed, 16 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/transform/ExplicitOuter.scala b/src/dotty/tools/dotc/transform/ExplicitOuter.scala index 912bc9b7f..eb231bfe7 100644 --- a/src/dotty/tools/dotc/transform/ExplicitOuter.scala +++ b/src/dotty/tools/dotc/transform/ExplicitOuter.scala @@ -136,7 +136,9 @@ object ExplicitOuter { /** A new outer accessor or param accessor */ private def newOuterSym(owner: ClassSymbol, cls: ClassSymbol, name: TermName, flags: FlagSet)(implicit ctx: Context) = { - ctx.newSymbol(owner, name, Synthetic | flags, cls.owner.enclosingClass.typeRef, coord = cls.coord) + val target = cls.owner.enclosingClass.typeRef + val info = if (flags.is(Method)) ExprType(target) else target + ctx.newSymbol(owner, name, Synthetic | flags, info, coord = cls.coord) } /** A new param accessor for the outer field in class `cls` */ @@ -302,7 +304,7 @@ object ExplicitOuter { val outerAccessorCtx = ctx.withPhaseNoLater(ctx.lambdaLiftPhase) // lambdalift mangles local class names, which means we cannot reliably find outer acessors anymore ctx.log(i"outer to $toCls of $tree: ${tree.tpe}, looking for ${outerAccName(treeCls.asClass)(outerAccessorCtx)} in $treeCls") if (treeCls == toCls) tree - else loop(tree select outerAccessor(treeCls.asClass)(outerAccessorCtx)) + else loop(tree.select(outerAccessor(treeCls.asClass)(outerAccessorCtx)).ensureApplied) } ctx.log(i"computing outerpath to $toCls from ${ctx.outersIterator.map(_.owner).toList}") loop(This(ctx.owner.enclosingClass.asClass)) diff --git a/tests/run/i659.scala b/tests/run/i659.scala new file mode 100644 index 000000000..5f10f15e8 --- /dev/null +++ b/tests/run/i659.scala @@ -0,0 +1,12 @@ +class Foo(val a: Int) { + //def foo = { {case x => x + a}: PartialFunction[Int, Int]} + class Bar { def result(x: Int) = x + a } + def bar = new Bar +} + +object Test extends dotty.runtime.LegacyApp { + //val x = new Foo(1).foo.apply(2) + val y = new Foo(1).bar.result(2) + assert(y == 3, y) + //assert(x == 3, x) +} |