diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 0fc52dc5e88e..733a54705da1 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -1363,7 +1363,10 @@ trait Applications extends Compatibility { */ def hasExtensionMethodNamed(tp: Type, xname: TermName, argType: Type, resultType: Type)(using Context) = { def qualifies(mbr: Denotation) = - mbr.exists && isApplicableType(tp.select(xname, mbr), argType :: Nil, resultType) + mbr.exists + && isApplicableType( + normalize(tp.select(xname, mbr), WildcardType), + argType :: Nil, resultType) tp.memberBasedOnFlags(xname, required = ExtensionMethod) match { case mbr: SingleDenotation => qualifies(mbr) case mbr => mbr.hasAltWith(qualifies(_)) diff --git a/tests/pos/i9530.scala b/tests/pos/i9530.scala new file mode 100644 index 000000000000..469ce8d89782 --- /dev/null +++ b/tests/pos/i9530.scala @@ -0,0 +1,37 @@ +trait Food +case class Banana(color: String) extends Food + +trait Diet[A <: Animal]: + type F <: Food + def food: Seq[F] + +trait Animal +object Animal: + extension [A <: Animal](using diet: Diet[A])(animal: A) def food1 = diet.food + extension [A <: Animal](animal: A)(using diet: Diet[A]) def food2 = diet.food + +extension [A <: Animal](using diet: Diet[A])(animal: A) def food3 = diet.food +extension [A <: Animal](animal: A)(using diet: Diet[A]) def food4 = diet.food + +trait Monkey extends Animal + +given Diet[Monkey] with + type F = Banana + def food: Seq[Banana] = Seq(new Banana("yellow"), Banana("green")) + +trait FoodOps +given FoodOps with + extension [A <: Animal](using diet: Diet[A])(animal: A) def food5 = diet.food + extension [A <: Animal](animal: A)(using diet: Diet[A]) def food6 = diet.food + + +val monkey = new Monkey {} + +val foods = Seq( + monkey.food1, // doesn't compile + monkey.food2, // compiles + monkey.food3, // compiles + monkey.food4, // compiles + monkey.food5, // doesn't compile + monkey.food6, // compiles +)