Skip to content

Commit 5310c94

Browse files
committed
Workaround #1895: Bringing a symbol to a new run is broken
1 parent c11d852 commit 5310c94

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@ trait SymDenotations { this: Context =>
4545
else {
4646
val initial = denot.initial
4747
val firstPhaseId = initial.validFor.firstPhaseId.max(ctx.typerPhase.id)
48-
if ((initial ne denot) || ctx.phaseId != firstPhaseId)
49-
ctx.withPhase(firstPhaseId).stillValidInOwner(initial)
50-
else
48+
if ((initial ne denot) || ctx.phaseId != firstPhaseId) {
49+
ctx.withPhase(firstPhaseId).stillValidInOwner(initial) ||
50+
// Workaround #1895: A symbol might not be entered into an owner
51+
// until the second phase where it exists
52+
(denot.validFor.containsPhaseId(firstPhaseId + 1)) &&
53+
ctx.withPhase(firstPhaseId + 1).stillValidInOwner(initial)
54+
} else
5155
stillValidInOwner(denot)
5256
}
5357

compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@ class ExtensionMethods extends MiniPhaseTransform with DenotTransformer with Ful
6363
// not generate them again.
6464
if (!(valueClass is Scala2x)) ctx.atPhase(thisTransformer) { implicit ctx =>
6565
for (decl <- valueClass.classInfo.decls) {
66-
if (isMethodWithExtension(decl))
67-
decls1.enter(createExtensionMethod(decl, moduleClassSym.symbol))
66+
if (isMethodWithExtension(decl)) {
67+
val meth = createExtensionMethod(decl, moduleClassSym.symbol)
68+
decls1.enter(meth)
69+
// Workaround #1895: force denotation of `meth` to be
70+
// at phase where `meth` is entered into the decls of a class
71+
meth.denot(ctx.withPhase(thisTransformer.next))
72+
}
6873
}
6974
}
7075

tests/repl/vc.check

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
scala> class Foo(x: Int) extends AnyVal { def hi: Int = 1 }
2+
defined class Foo
3+
scala> new Foo(1).hi
4+
val res0: Int = 1
5+
scala> :quit

0 commit comments

Comments
 (0)