@@ -574,13 +574,17 @@ class Typer extends Namer
574574 checkLegalValue(select, pt)
575575 ConstFold (select)
576576 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.
578580 typedSelect(tree, pt, qual)
579581 else
580582 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 )
582584 if ! tree1.isEmpty then
583585 tree1
586+ else if canDefineFurther(qual.tpe.widen) then
587+ typedSelect(tree, pt, qual)
584588 else if qual.tpe.derivesFrom(defn.DynamicClass )
585589 && selName.isTermName && ! isDynamicExpansion(tree)
586590 then
@@ -3038,7 +3042,7 @@ class Typer extends Namer
30383042 if selProto.isMatchedBy(qual.tpe) then None
30393043 else
30403044 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 )
30423046 if tree1.isEmpty then None
30433047 else Some (adapt(tree1, pt, locked))
30443048 } { (_, _) => None
@@ -3052,10 +3056,10 @@ class Typer extends Namer
30523056 * @return The converted tree, or `EmptyTree` is not successful.
30533057 */
30543058 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 )
30563060 (using Context ): Tree =
30573061
3058- def selectionProto = SelectionProto (tree.name, mbrProto, compat, privateOK)
3062+ def selectionProto = SelectionProto (tree.name, mbrProto, compat, privateOK = inSelect )
30593063
30603064 def tryExtension (using Context ): Tree =
30613065 findRef(tree.name, WildcardType , ExtensionMethod , EmptyFlags , qual.srcPos) match
@@ -3093,12 +3097,13 @@ class Typer extends Namer
30933097 return typedSelect(tree, pt, found)
30943098 case failure : SearchFailure =>
30953099 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)
30993105 else
31003106 err.typeMismatch(qual, selProto, failure.reason) // TODO: report NotAMember instead, but need to be aware of failure
3101- )
31023107 rememberSearchFailure(qual, failure)
31033108 }
31043109 catch case ex : TypeError => nestedFailure(ex)
0 commit comments