File tree Expand file tree Collapse file tree 3 files changed +19
-5
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +19
-5
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments