@@ -1100,7 +1100,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
1100
1100
adaptConstant(value)
1101
1101
case OverloadedType (pre, alts) if ! mode.inFunMode => // (1)
1102
1102
inferExprAlternative(tree, pt)
1103
- adapt (tree, mode, pt, original)
1103
+ adaptAfterOverloadResolution (tree, mode, pt, original)
1104
1104
case NullaryMethodType (restpe) => // (2)
1105
1105
adapt(tree setType restpe, mode, pt, original)
1106
1106
case TypeRef (_, ByNameParamClass , arg :: Nil ) if mode.inExprMode => // (2)
@@ -1133,6 +1133,12 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
1133
1133
}
1134
1134
}
1135
1135
1136
+ // This just exists to help keep track of the spots where we have to adapt a tree after
1137
+ // overload resolution. These proved hard to find during the fix for SI-8267.
1138
+ def adaptAfterOverloadResolution (tree : Tree , mode : Mode , pt : Type = WildcardType , original : Tree = EmptyTree ): Tree = {
1139
+ adapt(tree, mode, pt, original)
1140
+ }
1141
+
1136
1142
def instantiate (tree : Tree , mode : Mode , pt : Type ): Tree = {
1137
1143
inferExprInstance(tree, context.extractUndetparams(), pt)
1138
1144
adapt(tree, mode, pt)
@@ -3171,7 +3177,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
3171
3177
if (sym1 != NoSymbol ) sym = sym1
3172
3178
}
3173
3179
if (sym == NoSymbol ) fun
3174
- else adapt (fun setSymbol sym setType pre.memberType(sym), mode.forFunMode, WildcardType )
3180
+ else adaptAfterOverloadResolution (fun setSymbol sym setType pre.memberType(sym), mode.forFunMode)
3175
3181
} else fun
3176
3182
}
3177
3183
@@ -3216,7 +3222,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
3216
3222
setError(tree)
3217
3223
else {
3218
3224
inferMethodAlternative(fun, undetparams, argTpes, pt)
3219
- doTypedApply(tree, adapt (fun, mode.forFunMode, WildcardType ), args1, mode, pt)
3225
+ doTypedApply(tree, adaptAfterOverloadResolution (fun, mode.forFunMode, WildcardType ), args1, mode, pt)
3220
3226
}
3221
3227
}
3222
3228
handleOverloaded
@@ -3799,7 +3805,18 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
3799
3805
protected def typedTypeApply (tree : Tree , mode : Mode , fun : Tree , args : List [Tree ]): Tree = fun.tpe match {
3800
3806
case OverloadedType (pre, alts) =>
3801
3807
inferPolyAlternatives(fun, mapList(args)(treeTpe))
3802
- val tparams = fun.symbol.typeParams // @M TODO: fun.symbol.info.typeParams ? (as in typedAppliedTypeTree)
3808
+
3809
+ // SI-8267 `memberType` can introduce existentials *around* a PolyType/MethodType, see AsSeenFromMap#captureThis.
3810
+ // If we had selected a non-overloaded symbol, `memberType` would have been called in `makeAccessible`
3811
+ // and the resulting existential type would have been skolemized in `adapt` *before* we typechecked
3812
+ // the enclosing type-/ value- application.
3813
+ //
3814
+ // However, if the selection is overloaded, we defer calling `memberType` until we can select a single
3815
+ // alternative here. It is therefore necessary to skolemize the existential here.
3816
+ //
3817
+ val fun1 = adaptAfterOverloadResolution(fun, mode.forFunMode | TAPPmode )
3818
+
3819
+ val tparams = fun1.symbol.typeParams // @M TODO: fun.symbol.info.typeParams ? (as in typedAppliedTypeTree)
3803
3820
val args1 = if (sameLength(args, tparams)) {
3804
3821
// @M: in case TypeApply we can't check the kind-arities of the type arguments,
3805
3822
// as we don't know which alternative to choose... here we do
@@ -3813,7 +3830,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
3813
3830
// ...actually this was looping anyway, see bug #278.
3814
3831
return TypedApplyWrongNumberOfTpeParametersError (fun, fun)
3815
3832
3816
- typedTypeApply(tree, mode, fun , args1)
3833
+ typedTypeApply(tree, mode, fun1 , args1)
3817
3834
case SingleType (_, _) =>
3818
3835
typedTypeApply(tree, mode, fun setType fun.tpe.widen, args)
3819
3836
case PolyType (tparams, restpe) if tparams.nonEmpty =>
0 commit comments