@@ -450,27 +450,30 @@ class Typer extends Namer
450450 if (name == nme.ROOTPKG )
451451 return tree.withType(defn.RootPackage .termRef)
452452
453- val rawType = {
453+ val rawType =
454454 val saved1 = unimported
455455 val saved2 = foundUnderScala2
456456 unimported = Set .empty
457457 foundUnderScala2 = NoType
458- try {
459- var found = findRef(name, pt, EmptyFlags , tree.srcPos)
460- if ( foundUnderScala2.exists && ! (foundUnderScala2 =:= found)) {
458+ try
459+ val found = findRef(name, pt, EmptyFlags , tree.srcPos)
460+ if foundUnderScala2.exists && ! (foundUnderScala2 =:= found) then
461461 report.migrationWarning(
462462 ex """ Name resolution will change.
463463 | currently selected : $foundUnderScala2
464464 | in the future, without -source 3.0-migration: $found""" , tree.srcPos)
465- found = foundUnderScala2
466- }
467- found
468- }
469- finally {
465+ foundUnderScala2
466+ else
467+ found match
468+ case found : TermRef
469+ if ! found.denot.hasAltWith(! _.symbol.is(ExtensionMethod ))
470+ && ! pt.isExtensionApplyProto =>
471+ NoType // direct calls to extension methods need a prefix
472+ case _ =>
473+ found
474+ finally
470475 unimported = saved1
471476 foundUnderScala2 = saved2
472- }
473- }
474477
475478 def setType (ownType : Type ): Tree =
476479 val tree1 = ownType match
@@ -842,7 +845,9 @@ class Typer extends Namer
842845 case fn @ TypeApply (fn1, targs) =>
843846 untpd.cpy.TypeApply (fn)(toSetter(fn1), targs.map(untpd.TypedSplice (_)))
844847 case fn @ Apply (fn1, args) =>
845- val result = untpd.cpy.Apply (fn)(toSetter(fn1), args.map(untpd.TypedSplice (_)))
848+ val result = untpd.cpy.Apply (fn)(
849+ toSetter(fn1),
850+ args.map(untpd.TypedSplice (_, isExtensionReceiver = true )))
846851 fn1 match
847852 case Apply (_, _) => // current apply is to implicit arguments
848853 result.setApplyKind(ApplyKind .Using )
@@ -2947,7 +2952,15 @@ class Typer extends Namer
29472952 }
29482953
29492954 def adaptOverloaded (ref : TermRef ) = {
2950- val altDenots = ref.denot.alternatives
2955+ val altDenots =
2956+ val allDenots = ref.denot.alternatives
2957+ def isIdent = tree match
2958+ case _ : Ident => true
2959+ case Select (qual, name) => qual.span.isZeroExtent
2960+ case _ => false
2961+ if pt.isExtensionApplyProto then allDenots.filter(_.symbol.is(ExtensionMethod ))
2962+ else if isIdent then allDenots.filterNot(_.symbol.is(ExtensionMethod ))
2963+ else allDenots
29512964 typr.println(i " adapt overloaded $ref with alternatives ${altDenots map (_.info)}% \n\n % " )
29522965 def altRef (alt : SingleDenotation ) = TermRef (ref.prefix, ref.name, alt)
29532966 val alts = altDenots.map(altRef)
0 commit comments