From cb2c2a0ff1631df91f84a85b0db814b24a4d6d62 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Sun, 4 Dec 2016 22:23:02 +0100 Subject: Workaround #1770: Run changeOwner at group end in ElimByName Using changeOwnerAfter would be more appropriate but currently fails with an assertion in LambdaLift --- compiler/src/dotty/tools/dotc/transform/ElimByName.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'compiler/src/dotty/tools/dotc/transform') diff --git a/compiler/src/dotty/tools/dotc/transform/ElimByName.scala b/compiler/src/dotty/tools/dotc/transform/ElimByName.scala index 2814baf1e..0e187fc2e 100644 --- a/compiler/src/dotty/tools/dotc/transform/ElimByName.scala +++ b/compiler/src/dotty/tools/dotc/transform/ElimByName.scala @@ -81,7 +81,11 @@ class ElimByName extends MiniPhaseTransform with InfoTransformer { thisTransform val inSuper = if (ctx.mode.is(Mode.InSuperCall)) InSuperCall else EmptyFlags val meth = ctx.newSymbol( ctx.owner, nme.ANON_FUN, Synthetic | Method | inSuper, MethodType(Nil, Nil, argType)) - Closure(meth, _ => arg.changeOwner(ctx.owner, meth)) + Closure(meth, _ => + atGroupEnd { implicit ctx: Context => + arg.changeOwner(ctx.owner, meth) + } + ) } ref(defn.dummyApply).appliedToType(argType).appliedTo(argFun) case _ => -- cgit v1.2.3 From 51a458efeeebfeed6c357d56cf8afe5b06e86724 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Fri, 23 Dec 2016 15:49:15 +0100 Subject: Workaround #1895: Bringing a symbol to a new run is broken --- compiler/src/dotty/tools/dotc/core/SymDenotations.scala | 10 +++++++--- compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala | 9 +++++++-- tests/repl/vc.check | 5 +++++ 3 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 tests/repl/vc.check (limited to 'compiler/src/dotty/tools/dotc/transform') diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index aaae78c57..a3475e14c 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -45,9 +45,13 @@ trait SymDenotations { this: Context => else { val initial = denot.initial val firstPhaseId = initial.validFor.firstPhaseId.max(ctx.typerPhase.id) - if ((initial ne denot) || ctx.phaseId != firstPhaseId) - ctx.withPhase(firstPhaseId).stillValidInOwner(initial) - else + if ((initial ne denot) || ctx.phaseId != firstPhaseId) { + ctx.withPhase(firstPhaseId).stillValidInOwner(initial) || + // Workaround #1895: A symbol might not be entered into an owner + // until the second phase where it exists + (denot.validFor.containsPhaseId(firstPhaseId + 1)) && + ctx.withPhase(firstPhaseId + 1).stillValidInOwner(initial) + } else stillValidInOwner(denot) } diff --git a/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala b/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala index 925ec08b2..64474cecd 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala @@ -63,8 +63,13 @@ class ExtensionMethods extends MiniPhaseTransform with DenotTransformer with Ful // not generate them again. if (!(valueClass is Scala2x)) ctx.atPhase(thisTransformer) { implicit ctx => for (decl <- valueClass.classInfo.decls) { - if (isMethodWithExtension(decl)) - decls1.enter(createExtensionMethod(decl, moduleClassSym.symbol)) + if (isMethodWithExtension(decl)) { + val meth = createExtensionMethod(decl, moduleClassSym.symbol) + decls1.enter(meth) + // Workaround #1895: force denotation of `meth` to be + // at phase where `meth` is entered into the decls of a class + meth.denot(ctx.withPhase(thisTransformer.next)) + } } } diff --git a/tests/repl/vc.check b/tests/repl/vc.check new file mode 100644 index 000000000..e2c9b65fd --- /dev/null +++ b/tests/repl/vc.check @@ -0,0 +1,5 @@ +scala> class Foo(x: Int) extends AnyVal { def hi: Int = 1 } +defined class Foo +scala> new Foo(1).hi +val res0: Int = 1 +scala> :quit -- cgit v1.2.3