Skip to content

Commit 818e36c

Browse files
committed
Don't produce duplicate select effect in potential expansion
1 parent c49664d commit 818e36c

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

compiler/src/dotty/tools/dotc/transform/init/Checking.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ object Checking {
419419

420420
case _ =>
421421
val Summary(pots, effs) = expand(pot1)
422-
val Summary(pots2, effs2) = pots.select(sym, pot.source)
422+
val Summary(pots2, effs2) = pots.select(sym, pot.source, selectEffect = false)
423423
Summary(pots2, effs ++ effs2)
424424
}
425425

@@ -448,7 +448,7 @@ object Checking {
448448

449449
case _ =>
450450
val Summary(pots, effs) = expand(pot1)
451-
val Summary(pots2, effs2) = pots.select(sym, pot.source)
451+
val Summary(pots2, effs2) = pots.select(sym, pot.source, selectEffect = false)
452452
Summary(pots2, effs ++ effs2)
453453
}
454454

compiler/src/dotty/tools/dotc/transform/init/Potentials.scala

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,24 @@ object Potentials {
154154

155155
extension (pot: Potential) def toPots: Potentials = Potentials.empty + pot
156156

157-
extension (ps: Potentials) def select (symbol: Symbol, source: Tree)(using Context): Summary =
158-
ps.foldLeft(Summary.empty) { case (Summary(pots, effs), pot) =>
157+
extension (ps: Potentials) def select (symbol: Symbol, source: Tree, selectEffect: Boolean = true)(using Context): Summary =
158+
ps.foldLeft(Summary.empty) { case (summary, pot) =>
159159
// max potential length
160160
// TODO: it can be specified on a project basis via compiler options
161161
if (pot.size > 2)
162162
summary + Promote(pot)(pot.source)
163163
else if (symbol.isConstructor)
164-
Summary(pots + pot, effs + MethodCall(pot, symbol)(source))
164+
val res = summary + pot
165+
if selectEffect then res + MethodCall(pot, symbol)(source)
166+
else res
165167
else if (symbol.isOneOf(Flags.Method | Flags.Lazy))
166-
Summary(
167-
pots + MethodReturn(pot, symbol)(source),
168-
effs + MethodCall(pot, symbol)(source)
169-
)
168+
val res = summary + MethodReturn(pot, symbol)(source)
169+
if selectEffect then res + MethodCall(pot, symbol)(source)
170+
else res
170171
else
171-
Summary(pots + FieldReturn(pot, symbol)(source), effs + FieldAccess(pot, symbol)(source))
172+
val res = summary + FieldReturn(pot, symbol)(source)
173+
if selectEffect then res + FieldAccess(pot, symbol)(source)
174+
else res
172175
}
173176

174177
extension (ps: Potentials) def promote(source: Tree): Effects = ps.map(Promote(_)(source))

0 commit comments

Comments
 (0)