Skip to content

Commit badb96b

Browse files
committed
Inline clazz into if/else toremove lazy
1 parent 12be929 commit badb96b

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

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

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,37 +101,42 @@ class SuperAccessors(thisTransformer: DenotTransformer) {
101101
val Select(sup @ Super(_, mix), name) = sel
102102
val sym = sel.symbol
103103
assert(sup.symbol.exists, s"missing symbol in $sel: ${sup.tpe}")
104-
lazy val clazz = sup.symbol.asClass
105104

106-
if (sym.isTerm && !sym.is(Method, butNot = Accessor) && !ctx.owner.is(ParamForwarder))
105+
if (sym.isTerm && !sym.is(Method, butNot = Accessor) && !ctx.owner.is(ParamForwarder)) {
107106
// ParamForwaders as installed ParamForwarding.scala do use super calls to vals
108107
ctx.error(s"super may be not be used on ${sym.underlyingSymbol}", sel.pos)
109-
else if (isDisallowed(sym))
108+
sel
109+
} else if (isDisallowed(sym)) {
110110
ctx.error(s"super not allowed here: use this.${sel.name} instead", sel.pos)
111-
else if (sym is Deferred) {
112-
val member = sym.overridingSymbol(clazz)
113-
if (!mix.name.isEmpty ||
111+
sel
112+
} else {
113+
val clazz = sup.symbol.asClass
114+
if (sym is Deferred) {
115+
val member = sym.overridingSymbol(clazz)
116+
if (!mix.name.isEmpty ||
114117
!member.exists ||
115118
!((member is AbsOverride) && member.isIncompleteIn(clazz)))
116-
ctx.error(
119+
ctx.error(
117120
i"${sym.showLocated} is accessed from super. It may not be abstract unless it is overridden by a member declared `abstract' and `override'",
118121
sel.pos)
119-
else ctx.log(i"ok super $sel ${sym.showLocated} $member $clazz ${member.isIncompleteIn(clazz)}")
120-
}
121-
else if (mix.name.isEmpty && !(sym.owner is Trait))
122+
else ctx.log(i"ok super $sel ${sym.showLocated} $member $clazz ${member.isIncompleteIn(clazz)}")
123+
}
124+
else if (mix.name.isEmpty && !(sym.owner is Trait))
122125
// SI-4989 Check if an intermediate class between `clazz` and `sym.owner` redeclares the method as abstract.
123-
for (intermediateClass <- clazz.info.baseClasses.tail.takeWhile(_ != sym.owner)) {
124-
val overriding = sym.overridingSymbol(intermediateClass)
125-
if ((overriding is (Deferred, butNot = AbsOverride)) && !(overriding.owner is Trait))
126-
ctx.error(
126+
for (intermediateClass <- clazz.info.baseClasses.tail.takeWhile(_ != sym.owner)) {
127+
val overriding = sym.overridingSymbol(intermediateClass)
128+
if ((overriding is(Deferred, butNot = AbsOverride)) && !(overriding.owner is Trait))
129+
ctx.error(
127130
s"${sym.showLocated} cannot be directly accessed from ${clazz} because ${overriding.owner} redeclares it as abstract",
128131
sel.pos)
129132

130-
}
131-
if (name.isTermName && mix.name.isEmpty &&
132-
((clazz is Trait) || clazz != ctx.owner.enclosingClass || !validCurrentClass))
133-
superAccessorCall(sel)(ctx.withPhase(thisTransformer.next))
134-
else sel
133+
}
134+
135+
if (name.isTermName && mix.name.isEmpty &&
136+
((clazz is Trait) || clazz != ctx.owner.enclosingClass || !validCurrentClass))
137+
superAccessorCall(sel)(ctx.withPhase(thisTransformer.next))
138+
else sel
139+
}
135140
}
136141

137142
/** Disallow some super.XX calls targeting Any methods which would

0 commit comments

Comments
 (0)