@@ -937,30 +937,30 @@ trait Applications extends Compatibility {
937937 /** Type application where arguments come from prototype, and no implicits are inserted */
938938 def simpleApply (fun1 : Tree , proto : FunProto )(using Context ): Tree =
939939 methPart(fun1).tpe match {
940+ case funRef : TermRef if funRef.symbol.isSignaturePolymorphic =>
941+ // synthesize a method type based on the types at the call site.
942+ // one can imagine the original signature-polymorphic method as
943+ // being infinitely overloaded, with each individual overload only
944+ // being brought into existence as needed
945+ val originalResultType = funRef.symbol.info.resultType.stripNull
946+ val expectedResultType = AvoidWildcardsMap ()(proto.deepenProto.resultType)
947+ val resultType =
948+ if ! originalResultType.isRef(defn.ObjectClass ) then originalResultType
949+ else if isFullyDefined(expectedResultType, ForceDegree .all) then expectedResultType
950+ else expectedResultType match
951+ case SelectionProto (nme.asInstanceOf_, PolyProto (_, resTp), _, _) => resTp
952+ case _ => defn.ObjectType
953+ val info = MethodType (proto.typedArgs().map(_.tpe.widen), resultType)
954+ val sym2 = funRef.symbol.copy(info = info) // not entered, to avoid overload resolution problems
955+ val fun2 = fun1.withType(sym2.termRef)
956+ val app = simpleApply(fun2, proto)
957+ Typed (app, TypeTree (resultType))
940958 case funRef : TermRef =>
941- if defn.isPolymorphicSignature(funRef.symbol) then
942- val originalResultType = funRef.symbol.info.resultType.stripNull
943- val expectedResultType = AvoidWildcardsMap ()(proto.deepenProto.resultType)
944- val resultType =
945- if ! originalResultType.isRef(defn.ObjectClass ) then originalResultType
946- else if isFullyDefined(expectedResultType, ForceDegree .all) then expectedResultType
947- else expectedResultType match
948- case SelectionProto (nme.asInstanceOf_, PolyProto (_, resTp), _, _) => resTp
949- case _ => defn.ObjectType
950- // synthesize a method type based on the types at the call site.
951- // one can imagine the original signature-polymorphic method as
952- // being infinitely overloaded, with each individual overload only
953- // being brought into existence as needed
954- val info = MethodType (proto.typedArgs().map(_.tpe.widen), resultType)
955- val fun2 = fun1.withType(funRef.symbol.copy(info = info).termRef)
956- val app = simpleApply(fun2, proto)
957- Typed (app, TypeTree (resultType))
958- else
959- val app = ApplyTo (tree, fun1, funRef, proto, pt)
960- convertNewGenericArray(
961- widenEnumCase(
962- postProcessByNameArgs(funRef, app).computeNullable(),
963- pt))
959+ val app = ApplyTo (tree, fun1, funRef, proto, pt)
960+ convertNewGenericArray(
961+ widenEnumCase(
962+ postProcessByNameArgs(funRef, app).computeNullable(),
963+ pt))
964964 case _ =>
965965 handleUnexpectedFunType(tree, fun1)
966966 }
0 commit comments