Skip to content

Commit e3de5ac

Browse files
committed
Don't produce duplicate select effect in potential expansion
1 parent 93a8184 commit e3de5ac

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
@@ -345,7 +345,7 @@ object Checking {
345345

346346
case _ =>
347347
val Summary(pots, effs) = expand(pot1)
348-
val Summary(pots2, effs2) = pots.select(sym, pot.source)
348+
val Summary(pots2, effs2) = pots.select(sym, pot.source, selectEffect = false)
349349
Summary(pots2, effs ++ effs2)
350350
}
351351

@@ -374,7 +374,7 @@ object Checking {
374374

375375
case _ =>
376376
val Summary(pots, effs) = expand(pot1)
377-
val Summary(pots2, effs2) = pots.select(sym, pot.source)
377+
val Summary(pots2, effs2) = pots.select(sym, pot.source, selectEffect = false)
378378
Summary(pots2, effs ++ effs2)
379379
}
380380

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

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

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

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

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

0 commit comments

Comments
 (0)