@@ -903,6 +903,15 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
903903 def inlinedFromOutside (tree : Tree )(span : Span ): Tree =
904904 Inlined (EmptyTree , Nil , tree)(using ctx.withSource(inlinedMethod.topLevelClass.source)).withSpan(span)
905905
906+ // InlineCopier is a more fault-tolerant copier that does not cause errors when
907+ // function types in applications are undefined. This is necessary since we copy at
908+ // the same time as establishing the proper context in which the copied tree should
909+ // be evaluated. This matters for opaque types, see neg/i14653.scala.
910+ class InlineCopier () extends TypedTreeCopier :
911+ override def Apply (tree : Tree )(fun : Tree , args : List [Tree ])(using Context ): Apply =
912+ if fun.tpe.widen.exists then super .Apply (tree)(fun, args)
913+ else untpd.cpy.Apply (tree)(fun, args).withTypeUnchecked(tree.tpe)
914+
906915 // InlinerMap is a TreeTypeMap with special treatment for inlined arguments:
907916 // They are generally left alone (not mapped further, and if they wrap a type
908917 // the type Inlined wrapper gets dropped
@@ -913,7 +922,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
913922 newOwners : List [Symbol ],
914923 substFrom : List [Symbol ],
915924 substTo : List [Symbol ])(using Context )
916- extends TreeTypeMap (typeMap, treeMap, oldOwners, newOwners, substFrom, substTo):
925+ extends TreeTypeMap (
926+ typeMap, treeMap, oldOwners, newOwners, substFrom, substTo, InlineCopier ()):
917927
918928 override def copy (
919929 typeMap : Type => Type ,
0 commit comments