Skip to content

Commit 579f2a6

Browse files
authored
Merge pull request #220 from scala/backport-lts-3.3-22479
Backport "Fix stack overflow errors when generating opaque type proxies" to 3.3 LTS
2 parents c451553 + a76abab commit 579f2a6

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

compiler/src/dotty/tools/dotc/inlines/Inliner.scala

+5-1
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ class Inliner(val call: tpd.Tree)(using Context):
384384
*/
385385
private val opaqueProxies = new mutable.ListBuffer[(TermRef, TermRef)]
386386

387+
/** TermRefs for which we already started synthesising proxies */
388+
private val visitedTermRefs = new mutable.HashSet[TermRef]
389+
387390
protected def hasOpaqueProxies = opaqueProxies.nonEmpty
388391

389392
/** Map first halves of opaqueProxies pairs to second halves, using =:= as equality */
@@ -401,8 +404,9 @@ class Inliner(val call: tpd.Tree)(using Context):
401404
for cls <- ref.widen.baseClasses do
402405
if cls.containsOpaques
403406
&& (forThisProxy || inlinedMethod.isContainedIn(cls))
404-
&& mapRef(ref).isEmpty
407+
&& !visitedTermRefs.contains(ref)
405408
then
409+
visitedTermRefs += ref
406410
val refiningRef = OpaqueProxy(ref, cls, call.span)
407411
val refiningSym = refiningRef.symbol.asTerm
408412
val refinedType = refiningRef.info

tests/pos/i22468.scala

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Result.*
2+
opaque type Result[+E, +A] = Success[A] | Error[E]
3+
4+
object Result:
5+
opaque type Success[+A] = A
6+
sealed abstract class Error[+E]
7+
8+
extension [E, A](self: Result[E, A])
9+
inline def transform[B]: B = ???
10+
def problem: Boolean = transform[Boolean]

0 commit comments

Comments
 (0)