@@ -3730,9 +3730,35 @@ object Types extends TypeUtils {
3730
3730
def integrate (tparams : List [ParamInfo ], tp : Type )(using Context ): Type =
3731
3731
(tparams : @ unchecked) match {
3732
3732
case LambdaParam (lam, _) :: _ => tp.subst(lam, this ) // This is where the precondition is necessary.
3733
- case params : List [Symbol @ unchecked] => tp.subst (params, paramRefs)
3733
+ case params : List [Symbol @ unchecked] => IntegrateMap (params, paramRefs)(tp )
3734
3734
}
3735
3735
3736
+ /** A map that replaces references to symbols in `params` by the types in
3737
+ * `paramRefs`.
3738
+ *
3739
+ * It is similar to [[Substituters#subst ]] but avoids reloading denotations
3740
+ * of named types by overriding `derivedSelect`.
3741
+ *
3742
+ * This is needed because during integration, [[TermParamRef ]]s refer to a
3743
+ * [[LambdaType ]] that is not yet fully constructed, in particular for wich
3744
+ * `paramInfos` is `null`. In that case all [[TermParamRef ]]s have
3745
+ * [[NoType ]] as underlying type. Reloading denotions of selections
3746
+ * involving such [[TermParamRef ]]s in [[NamedType#withPrefix ]] could then
3747
+ * result in a [[NoDenotation ]], which would make later disambiguation of
3748
+ * overloads impossible. See `tests/pos/annot-17242.scala` for example.
3749
+ */
3750
+ private class IntegrateMap (params : List [Symbol ], paramRefs : List [Type ])(using Context ) extends TypeMap :
3751
+ override def apply (tp : Type ) =
3752
+ tp match
3753
+ case tp : NamedType if params.contains(tp.symbol) => paramRefs(params.indexOf(tp.symbol))
3754
+ case _ : BoundType | _ : ThisType => tp
3755
+ case _ => mapOver(tp)
3756
+
3757
+ override def derivedSelect (tp : NamedType , pre : Type ): Type =
3758
+ if tp.prefix eq pre then tp
3759
+ else if tp.symbol.exists then NamedType (pre, tp.name, tp.denot.asSeenFrom(pre))
3760
+ else NamedType (pre, tp.name)
3761
+
3736
3762
final def derivedLambdaType (paramNames : List [ThisName ] = this .paramNames,
3737
3763
paramInfos : List [PInfo ] = this .paramInfos,
3738
3764
resType : Type = this .resType)(using Context ): This =
0 commit comments