@@ -131,6 +131,39 @@ object Inliner:
131
131
case _ => tree
132
132
else super .transformInlined(tree)
133
133
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)
134
167
end Inliner
135
168
136
169
/** Produces an inlined version of `call` via its `inlined` method.
@@ -189,7 +222,7 @@ class Inliner(val call: tpd.Tree)(using Context):
189
222
private val bindingsBuf = new mutable.ListBuffer [ValOrDefDef ]
190
223
191
224
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)
193
226
194
227
/** A binding for the parameter of an inline method. This is a `val` def for
195
228
* by-value parameters and a `def` def for by-name parameters. `val` defs inherit
@@ -351,20 +384,9 @@ class Inliner(val call: tpd.Tree)(using Context):
351
384
&& (forThisProxy || inlinedMethod.isContainedIn(cls))
352
385
&& mapRef(ref).isEmpty
353
386
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
387
+ val refiningRef = OpaqueProxy (ref, cls, call.span)
388
+ val refiningSym = refiningRef.symbol.asTerm
389
+ val refinedType = refiningRef.info
368
390
val refiningDef = ValDef (refiningSym, tpd.ref(ref).cast(refinedType), inferred = true ).withSpan(span)
369
391
inlining.println(i " add opaque alias proxy $refiningDef for $ref in $tp" )
370
392
bindingsBuf += refiningDef
@@ -768,6 +790,7 @@ class Inliner(val call: tpd.Tree)(using Context):
768
790
override def typedSelect (tree : untpd.Select , pt : Type )(using Context ): Tree = {
769
791
val locked = ctx.typerState.ownedVars
770
792
val qual1 = typed(tree.qualifier, shallowSelectionProto(tree.name, pt, this , tree.nameSpan))
793
+ selectionType(tree, qual1) // side-effect
771
794
val resNoReduce = untpd.cpy.Select (tree)(qual1, tree.name).withType(tree.typeOpt)
772
795
val reducedProjection = reducer.reduceProjection(resNoReduce)
773
796
if reducedProjection.isType then
0 commit comments