@@ -94,6 +94,45 @@ object Inliner:
9494 false
9595 }
9696 end isElideableExpr
97+
98+ // InlineCopier is a more fault-tolerant copier that does not cause errors when
99+ // function types in applications are undefined. This is necessary since we copy at
100+ // the same time as establishing the proper context in which the copied tree should
101+ // be evaluated. This matters for opaque types, see neg/i14653.scala.
102+ private class InlineCopier () extends TypedTreeCopier :
103+ override def Apply (tree : Tree )(fun : Tree , args : List [Tree ])(using Context ): Apply =
104+ if fun.tpe.widen.exists then super .Apply (tree)(fun, args)
105+ else untpd.cpy.Apply (tree)(fun, args).withTypeUnchecked(tree.tpe)
106+
107+ // InlinerMap is a TreeTypeMap with special treatment for inlined arguments:
108+ // They are generally left alone (not mapped further, and if they wrap a type
109+ // the type Inlined wrapper gets dropped
110+ private class InlinerMap (
111+ typeMap : Type => Type ,
112+ treeMap : Tree => Tree ,
113+ oldOwners : List [Symbol ],
114+ newOwners : List [Symbol ],
115+ substFrom : List [Symbol ],
116+ substTo : List [Symbol ])(using Context )
117+ extends TreeTypeMap (
118+ typeMap, treeMap, oldOwners, newOwners, substFrom, substTo, InlineCopier ()):
119+
120+ override def copy (
121+ typeMap : Type => Type ,
122+ treeMap : Tree => Tree ,
123+ oldOwners : List [Symbol ],
124+ newOwners : List [Symbol ],
125+ substFrom : List [Symbol ],
126+ substTo : List [Symbol ])(using Context ) =
127+ new InlinerMap (typeMap, treeMap, oldOwners, newOwners, substFrom, substTo)
128+
129+ override def transformInlined (tree : Inlined )(using Context ) =
130+ if tree.call.isEmpty then
131+ tree.expansion match
132+ case expansion : TypeTree => expansion
133+ case _ => tree
134+ else super .transformInlined(tree)
135+ end InlinerMap
97136end Inliner
98137
99138/** Produces an inlined version of `call` via its `inlined` method.
@@ -496,45 +535,6 @@ class Inliner(val call: tpd.Tree)(using Context):
496535 def inlinedFromOutside (tree : Tree )(span : Span ): Tree =
497536 Inlined (EmptyTree , Nil , tree)(using ctx.withSource(inlinedMethod.topLevelClass.source)).withSpan(span)
498537
499- // InlineCopier is a more fault-tolerant copier that does not cause errors when
500- // function types in applications are undefined. This is necessary since we copy at
501- // the same time as establishing the proper context in which the copied tree should
502- // be evaluated. This matters for opaque types, see neg/i14653.scala.
503- class InlineCopier () extends TypedTreeCopier :
504- override def Apply (tree : Tree )(fun : Tree , args : List [Tree ])(using Context ): Apply =
505- if fun.tpe.widen.exists then super .Apply (tree)(fun, args)
506- else untpd.cpy.Apply (tree)(fun, args).withTypeUnchecked(tree.tpe)
507-
508- // InlinerMap is a TreeTypeMap with special treatment for inlined arguments:
509- // They are generally left alone (not mapped further, and if they wrap a type
510- // the type Inlined wrapper gets dropped
511- class InlinerMap (
512- typeMap : Type => Type ,
513- treeMap : Tree => Tree ,
514- oldOwners : List [Symbol ],
515- newOwners : List [Symbol ],
516- substFrom : List [Symbol ],
517- substTo : List [Symbol ])(using Context )
518- extends TreeTypeMap (
519- typeMap, treeMap, oldOwners, newOwners, substFrom, substTo, InlineCopier ()):
520-
521- override def copy (
522- typeMap : Type => Type ,
523- treeMap : Tree => Tree ,
524- oldOwners : List [Symbol ],
525- newOwners : List [Symbol ],
526- substFrom : List [Symbol ],
527- substTo : List [Symbol ])(using Context ) =
528- new InlinerMap (typeMap, treeMap, oldOwners, newOwners, substFrom, substTo)
529-
530- override def transformInlined (tree : Inlined )(using Context ) =
531- if tree.call.isEmpty then
532- tree.expansion match
533- case expansion : TypeTree => expansion
534- case _ => tree
535- else super .transformInlined(tree)
536- end InlinerMap
537-
538538 // A tree type map to prepare the inlined body for typechecked.
539539 // The translation maps references to `this` and parameters to
540540 // corresponding arguments or proxies on the type and term level. It also changes
0 commit comments