@@ -903,6 +903,15 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
903
903
def inlinedFromOutside (tree : Tree )(span : Span ): Tree =
904
904
Inlined (EmptyTree , Nil , tree)(using ctx.withSource(inlinedMethod.topLevelClass.source)).withSpan(span)
905
905
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
+
906
915
// InlinerMap is a TreeTypeMap with special treatment for inlined arguments:
907
916
// They are generally left alone (not mapped further, and if they wrap a type
908
917
// the type Inlined wrapper gets dropped
@@ -913,7 +922,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
913
922
newOwners : List [Symbol ],
914
923
substFrom : List [Symbol ],
915
924
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 ()):
917
927
918
928
override def copy (
919
929
typeMap : Type => Type ,
0 commit comments