Skip to content

Commit 0369f1e

Browse files
committed
Fix merge breakage
Lazy Scala2 fields and trait parameters touched the same code in Mixin and the merge dropped essential logic. Also cleaned up some of the code having to do with lazy Scala2 fields.
1 parent e4db53a commit 0369f1e

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/dotty/tools/dotc/transform/Mixin.scala

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,29 +193,32 @@ class Mixin extends MiniPhaseTransform with SymTransformer { thisTransform =>
193193
ctx.error(i"parameterized $mixin $msg", pos)
194194
EmptyTree
195195
}
196+
196197
for (getter <- mixin.info.decls.filter(getr => getr.isGetter && !wasDeferred(getr)).toList) yield {
197198
val isScala2x = mixin.is(Scala2x)
198199
def default = Underscore(getter.info.resultType)
199200
def initial = transformFollowing(superRef(initializer(getter)).appliedToNone)
201+
202+
/** A call to the implementation of `getter` in `mixin`'s implementation class */
203+
def lazyGetterCall = {
204+
def canbeImplClassGetter(sym: Symbol) = sym.info.firstParamTypes match {
205+
case t :: Nil => t.isDirectRef(mixin)
206+
case _ => false
207+
}
208+
val implClassGetter = mixin.implClass.info.nonPrivateDecl(getter.name)
209+
.suchThat(canbeImplClassGetter).symbol
210+
ref(mixin.implClass).select(implClassGetter).appliedTo(This(cls))
211+
}
212+
200213
if (isCurrent(getter) || getter.is(ExpandedName)) {
201214
val rhs =
202215
if (ctx.atPhase(thisTransform)(implicit ctx => getter.is(ParamAccessor))) nextArgument()
203-
else if (isScala2x) Underscore(getter.info.resultType)
216+
else if (isScala2x)
217+
if (getter.is(Lazy)) lazyGetterCall
218+
else Underscore(getter.info.resultType)
204219
else transformFollowing(superRef(initializer(getter)).appliedToNone)
205220
// transformFollowing call is needed to make memoize & lazy vals run
206-
transformFollowing(
207-
DefDef(implementation(getter.asTerm),
208-
if (isScala2x) {
209-
if (getter.is(Flags.Lazy)) { // lazy vals need to have a rhs that will be the lazy initializer
210-
val sym = mixin.implClass.info.nonPrivateDecl(getter.name).suchThat(_.info.paramTypess match {
211-
case List(List(t: TypeRef)) => t.isDirectRef(mixin)
212-
case _ => false
213-
}).symbol // lazy val can be overloaded
214-
ref(mixin.implClass).select(sym).appliedTo(This(ctx.owner.asClass))
215-
}
216-
else default
217-
} else initial)
218-
)
221+
transformFollowing(DefDef(implementation(getter.asTerm), rhs))
219222
}
220223
else if (isScala2x) EmptyTree
221224
else initial

0 commit comments

Comments
 (0)