Skip to content

Backport "Fix stack overflow errors when generating opaque type proxies" to 3.3 LTS #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/inlines/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ class Inliner(val call: tpd.Tree)(using Context):
*/
private val opaqueProxies = new mutable.ListBuffer[(TermRef, TermRef)]

/** TermRefs for which we already started synthesising proxies */
private val visitedTermRefs = new mutable.HashSet[TermRef]

protected def hasOpaqueProxies = opaqueProxies.nonEmpty

/** Map first halves of opaqueProxies pairs to second halves, using =:= as equality */
Expand All @@ -401,8 +404,9 @@ class Inliner(val call: tpd.Tree)(using Context):
for cls <- ref.widen.baseClasses do
if cls.containsOpaques
&& (forThisProxy || inlinedMethod.isContainedIn(cls))
&& mapRef(ref).isEmpty
&& !visitedTermRefs.contains(ref)
then
visitedTermRefs += ref
val refiningRef = OpaqueProxy(ref, cls, call.span)
val refiningSym = refiningRef.symbol.asTerm
val refinedType = refiningRef.info
Expand Down
10 changes: 10 additions & 0 deletions tests/pos/i22468.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Result.*
opaque type Result[+E, +A] = Success[A] | Error[E]

object Result:
opaque type Success[+A] = A
sealed abstract class Error[+E]

extension [E, A](self: Result[E, A])
inline def transform[B]: B = ???
def problem: Boolean = transform[Boolean]