@@ -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 where 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
@@ -3038,7 +3042,7 @@ class Typer extends Namer
3038
3042
if selProto.isMatchedBy(qual.tpe) then None
3039
3043
else
3040
3044
tryEither {
3041
- val tree1 = tryExtensionOrConversion(tree, pt, pt, qual, locked, NoViewsAllowed , privateOK = false )
3045
+ val tree1 = tryExtensionOrConversion(tree, pt, pt, qual, locked, NoViewsAllowed , inSelect = false )
3042
3046
if tree1.isEmpty then None
3043
3047
else Some (adapt(tree1, pt, locked))
3044
3048
} { (_, _) => None
@@ -3052,10 +3056,10 @@ class Typer extends Namer
3052
3056
* @return The converted tree, or `EmptyTree` is not successful.
3053
3057
*/
3054
3058
def tryExtensionOrConversion
3055
- (tree : untpd.Select , pt : Type , mbrProto : Type , qual : Tree , locked : TypeVars , compat : Compatibility , privateOK : Boolean )
3059
+ (tree : untpd.Select , pt : Type , mbrProto : Type , qual : Tree , locked : TypeVars , compat : Compatibility , inSelect : Boolean )
3056
3060
(using Context ): Tree =
3057
3061
3058
- def selectionProto = SelectionProto (tree.name, mbrProto, compat, privateOK)
3062
+ def selectionProto = SelectionProto (tree.name, mbrProto, compat, privateOK = inSelect )
3059
3063
3060
3064
def tryExtension (using Context ): Tree =
3061
3065
findRef(tree.name, WildcardType , ExtensionMethod , EmptyFlags , qual.srcPos) match
@@ -3093,12 +3097,13 @@ class Typer extends Namer
3093
3097
return typedSelect(tree, pt, found)
3094
3098
case failure : SearchFailure =>
3095
3099
if failure.isAmbiguous then
3096
- return (
3097
- if canDefineFurther(qual.tpe.widen) then
3098
- tryExtensionOrConversion(tree, pt, mbrProto, qual, locked, compat, privateOK)
3100
+ return
3101
+ if ! inSelect // in a selection we will do the canDefineFurther afterwards
3102
+ && canDefineFurther(qual.tpe.widen)
3103
+ then
3104
+ tryExtensionOrConversion(tree, pt, mbrProto, qual, locked, compat, inSelect)
3099
3105
else
3100
3106
err.typeMismatch(qual, selProto, failure.reason) // TODO: report NotAMember instead, but need to be aware of failure
3101
- )
3102
3107
rememberSearchFailure(qual, failure)
3103
3108
}
3104
3109
catch case ex : TypeError => nestedFailure(ex)
0 commit comments