@@ -131,6 +131,39 @@ object Inliner:
131131 case _ => tree
132132 else super .transformInlined(tree)
133133 end InlinerMap
134+
135+ object OpaqueProxy :
136+
137+ def apply (ref : TermRef , cls : ClassSymbol , span : Span )(using Context ): TermRef =
138+ def openOpaqueAliases (selfType : Type ): List [(Name , Type )] = selfType match
139+ case RefinedType (parent, rname, TypeAlias (alias)) =>
140+ val opaq = cls.info.member(rname).symbol
141+ if opaq.isOpaqueAlias then
142+ (rname, alias.stripLazyRef.asSeenFrom(ref, cls))
143+ :: openOpaqueAliases(parent)
144+ else Nil
145+ case _ => Nil
146+ val refinements = openOpaqueAliases(cls.givenSelfType)
147+ val refinedType = refinements.foldLeft(ref : Type ): (parent, refinement) =>
148+ RefinedType (parent, refinement._1, TypeAlias (refinement._2))
149+ val refiningSym = newSym(InlineBinderName .fresh(), Synthetic , refinedType, span)
150+ refiningSym.termRef
151+
152+ def unapply (refiningRef : TermRef )(using Context ): Option [TermRef ] =
153+ val refiningSym = refiningRef.symbol
154+ if refiningSym.name.is(InlineBinderName ) && refiningSym.is(Synthetic , butNot= InlineProxy ) then
155+ refiningRef.info match
156+ case refinedType : RefinedType => refinedType.stripRefinement match
157+ case ref : TermRef => Some (ref)
158+ case _ => None
159+ case _ => None
160+ else
161+ None
162+
163+ end OpaqueProxy
164+
165+ private [inlines] def newSym (name : Name , flags : FlagSet , info : Type , span : Span )(using Context ): Symbol =
166+ newSymbol(ctx.owner, name, flags, info, coord = span)
134167end Inliner
135168
136169/** Produces an inlined version of `call` via its `inlined` method.
@@ -189,7 +222,7 @@ class Inliner(val call: tpd.Tree)(using Context):
189222 private val bindingsBuf = new mutable.ListBuffer [ValOrDefDef ]
190223
191224 private [inlines] def newSym (name : Name , flags : FlagSet , info : Type )(using Context ): Symbol =
192- newSymbol(ctx.owner, name, flags, info, coord = call.span)
225+ Inliner .newSym( name, flags, info, call.span)
193226
194227 /** A binding for the parameter of an inline method. This is a `val` def for
195228 * by-value parameters and a `def` def for by-name parameters. `val` defs inherit
@@ -351,21 +384,10 @@ class Inliner(val call: tpd.Tree)(using Context):
351384 && (forThisProxy || inlinedMethod.isContainedIn(cls))
352385 && mapRef(ref).isEmpty
353386 then
354- def openOpaqueAliases (selfType : Type ): List [(Name , Type )] = selfType match
355- case RefinedType (parent, rname, TypeAlias (alias)) =>
356- val opaq = cls.info.member(rname).symbol
357- if opaq.isOpaqueAlias then
358- (rname, alias.stripLazyRef.asSeenFrom(ref, cls))
359- :: openOpaqueAliases(parent)
360- else Nil
361- case _ =>
362- Nil
363- val refinements = openOpaqueAliases(cls.givenSelfType)
364- val refinedType = refinements.foldLeft(ref : Type ) ((parent, refinement) =>
365- RefinedType (parent, refinement._1, TypeAlias (refinement._2))
366- )
367- val refiningSym = newSym(InlineBinderName .fresh(), Synthetic , refinedType).asTerm
368- val refiningDef = ValDef (refiningSym, tpd.ref(ref).cast(refinedType)).withSpan(span)
387+ val refiningRef = OpaqueProxy (ref, cls, call.span)
388+ val refiningSym = refiningRef.symbol.asTerm
389+ val refinedType = refiningRef.info
390+ val refiningDef = ValDef (refiningSym, tpd.ref(ref).cast(refinedType), inferred = true ).withSpan(span)
369391 inlining.println(i " add opaque alias proxy $refiningDef for $ref in $tp" )
370392 bindingsBuf += refiningDef
371393 opaqueProxies += ((ref, refiningSym.termRef))
@@ -768,6 +790,7 @@ class Inliner(val call: tpd.Tree)(using Context):
768790 override def typedSelect (tree : untpd.Select , pt : Type )(using Context ): Tree = {
769791 val locked = ctx.typerState.ownedVars
770792 val qual1 = typed(tree.qualifier, shallowSelectionProto(tree.name, pt, this , tree.nameSpan))
793+ selectionType(tree, qual1) // side-effect
771794 val resNoReduce = untpd.cpy.Select (tree)(qual1, tree.name).withType(tree.typeOpt)
772795 val reducedProjection = reducer.reduceProjection(resNoReduce)
773796 if reducedProjection.isType then
0 commit comments