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