@@ -574,13 +574,17 @@ class Typer extends Namer
574
574
checkLegalValue(select, pt)
575
575
ConstFold (select)
576
576
else if couldInstantiateTypeVar(qual.tpe.widen) then
577
- // try again with more defined qualifier type
577
+ // there's a simply visible type variable in the result; try again with a more defined qualifier type
578
+ // There's a second trial wherw we try to instantiate all type variables in `qual.tpe.widen`,
579
+ // but that is done only after we search for extension methods or conversions.
578
580
typedSelect(tree, pt, qual)
579
581
else
580
582
val tree1 = tryExtensionOrConversion(
581
- tree, pt, IgnoredProto (pt), qual, ctx.typerState.ownedVars, this , privateOK = true )
583
+ tree, pt, IgnoredProto (pt), qual, ctx.typerState.ownedVars, this , inSelect = true )
582
584
if ! tree1.isEmpty then
583
585
tree1
586
+ else if canDefineFurther(qual.tpe.widen) then
587
+ typedSelect(tree, pt, qual)
584
588
else if qual.tpe.derivesFrom(defn.DynamicClass )
585
589
&& selName.isTermName && ! isDynamicExpansion(tree)
586
590
then
@@ -3037,7 +3041,7 @@ class Typer extends Namer
3037
3041
if selProto.isMatchedBy(qual.tpe) then None
3038
3042
else
3039
3043
tryEither {
3040
- val tree1 = tryExtensionOrConversion(tree, pt, pt, qual, locked, NoViewsAllowed , privateOK = false )
3044
+ val tree1 = tryExtensionOrConversion(tree, pt, pt, qual, locked, NoViewsAllowed , inSelect = false )
3041
3045
if tree1.isEmpty then None
3042
3046
else Some (adapt(tree1, pt, locked))
3043
3047
} { (_, _) => None
@@ -3051,10 +3055,10 @@ class Typer extends Namer
3051
3055
* @return The converted tree, or `EmptyTree` is not successful.
3052
3056
*/
3053
3057
def tryExtensionOrConversion
3054
- (tree : untpd.Select , pt : Type , mbrProto : Type , qual : Tree , locked : TypeVars , compat : Compatibility , privateOK : Boolean )
3058
+ (tree : untpd.Select , pt : Type , mbrProto : Type , qual : Tree , locked : TypeVars , compat : Compatibility , inSelect : Boolean )
3055
3059
(using Context ): Tree =
3056
3060
3057
- def selectionProto = SelectionProto (tree.name, mbrProto, compat, privateOK)
3061
+ def selectionProto = SelectionProto (tree.name, mbrProto, compat, privateOK = inSelect )
3058
3062
3059
3063
def tryExtension (using Context ): Tree =
3060
3064
findRef(tree.name, WildcardType , ExtensionMethod , EmptyFlags , qual.srcPos) match
@@ -3092,12 +3096,13 @@ class Typer extends Namer
3092
3096
return typedSelect(tree, pt, found)
3093
3097
case failure : SearchFailure =>
3094
3098
if failure.isAmbiguous then
3095
- return (
3096
- if canDefineFurther(qual.tpe.widen) then
3097
- tryExtensionOrConversion(tree, pt, mbrProto, qual, locked, compat, privateOK)
3099
+ return
3100
+ if ! inSelect // in a selection we will do the canDefineFurther afterwards
3101
+ && canDefineFurther(qual.tpe.widen)
3102
+ then
3103
+ tryExtensionOrConversion(tree, pt, mbrProto, qual, locked, compat, inSelect)
3098
3104
else
3099
3105
err.typeMismatch(qual, selProto, failure.reason) // TODO: report NotAMember instead, but need to be aware of failure
3100
- )
3101
3106
rememberSearchFailure(qual, failure)
3102
3107
}
3103
3108
catch case ex : TypeError => nestedFailure(ex)
0 commit comments