@@ -445,6 +445,9 @@ class Inliner(val call: tpd.Tree)(using Context):
445445
446446 /** Map back all TermRefs that match the right element in `opaqueProxies` to the
447447 * corresponding left element.
448+ * E.g. for a previously created
449+ * `val proxy$1 = Time {type OpaqueInt = Int}` as part of the ongoing inlining
450+ * a `List[proxy$1.OpaqueInt]` will be mapped back into a `List[Time.OpaqueInt]`.
448451 */
449452 protected val mapBackToOpaques = TreeTypeMap (
450453 typeMap = new TypeMap :
@@ -507,8 +510,19 @@ class Inliner(val call: tpd.Tree)(using Context):
507510
508511 def thisTypeProxyExists = ! thisProxy.isEmpty
509512
510- // Unpacks `val ObjectDef$_this: ObjectDef.type = ObjectDef` reference back into ObjectDef reference
511- // For nested transparent inline calls, ObjectDef will be an another proxy, but that is okay
513+ /** Maps a type that includes a thisProxy (e.g. `TermRef(NoPrefix,val Foo$_this)`)
514+ * by reading the defTree belonging to that thisProxy (`val Foo$_this: Foo.type = AnotherProxy`)
515+ * back into its original reference (`AnotherProxy`, which is directly or indirectly a refinement on `Foo`)
516+ *
517+ * Usually when we end up with another proxy like this, we will be able to further unwrap it back
518+ * into `Foo` with mapBackToOpaques, but, for nested transparent inline calls, `AnotherProxy` will be
519+ * a proxy created by inlining the outer calls, that we might not be able to further unwrap this way
520+ * (as those proxies will not be a part of opaqueProxies created during this inlining).
521+ * We leave that as it is and treat this behavior as intended (see documentation with an example in
522+ * `Opaque Types in Transparent Inline Methods` section in `opaques-details.md`),
523+ * as we might need those opaques to have visible right hand sides for successful
524+ * typechecking of the outer inline call.
525+ */
512526 val thisTypeUnpacker =
513527 TreeTypeMap (
514528 typeMap = new TypeMap :
@@ -522,6 +536,15 @@ class Inliner(val call: tpd.Tree)(using Context):
522536 }
523537 )
524538
539+ /** Returns the result type of the Inlined code block after removing thisProxy and opaqueProxy TermRefs.
540+ * E.g. for an Inlined tree returning Block of type `Option[Foo$_this.OpaqueInt]`,
541+ * and for proxies:
542+ * ```
543+ * val $proxy1: Foo.type{type OpaqueInt = Int} = = ...
544+ * val Foo$_this: ($proxy1 : Foo.type{type OpaqueInt = Int}) = ...
545+ * ```
546+ * the method will return: `Foo.OpaqueInt`
547+ */
525548 def unpackProxiesFromResultType (inlined : Inlined ): Type =
526549 if thisTypeProxyExists then mapBackToOpaques.typeMap(thisTypeUnpacker.typeMap(inlined.expansion.tpe))
527550 else inlined.tpe
0 commit comments