@@ -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 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.
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
@@ -3037,7 +3041,7 @@ class Typer extends Namer
30373041 if selProto.isMatchedBy(qual.tpe) then None
30383042 else
30393043 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 )
30413045 if tree1.isEmpty then None
30423046 else Some (adapt(tree1, pt, locked))
30433047 } { (_, _) => None
@@ -3051,10 +3055,10 @@ class Typer extends Namer
30513055 * @return The converted tree, or `EmptyTree` is not successful.
30523056 */
30533057 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 )
30553059 (using Context ): Tree =
30563060
3057- def selectionProto = SelectionProto (tree.name, mbrProto, compat, privateOK)
3061+ def selectionProto = SelectionProto (tree.name, mbrProto, compat, privateOK = inSelect )
30583062
30593063 def tryExtension (using Context ): Tree =
30603064 findRef(tree.name, WildcardType , ExtensionMethod , EmptyFlags , qual.srcPos) match
@@ -3092,12 +3096,13 @@ class Typer extends Namer
30923096 return typedSelect(tree, pt, found)
30933097 case failure : SearchFailure =>
30943098 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)
30983104 else
30993105 err.typeMismatch(qual, selProto, failure.reason) // TODO: report NotAMember instead, but need to be aware of failure
3100- )
31013106 rememberSearchFailure(qual, failure)
31023107 }
31033108 catch case ex : TypeError => nestedFailure(ex)
0 commit comments