diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 24b9bfbd9ed6..fb05af087a19 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -1780,14 +1780,20 @@ trait Applications extends Compatibility { def winsType2 = isAsSpecific(alt2, tp2, alt1, tp1) overload.println(i"compare($alt1, $alt2)? $tp1 $tp2 $ownerScore $winsType1 $winsType2") - if (ownerScore == 1) - if (winsType1 || !winsType2) 1 else 0 - else if (ownerScore == -1) - if (winsType2 || !winsType1) -1 else 0 - else if (winsType1) - if (winsType2) 0 else 1 + if winsType1 && winsType2 + && alt1.widenExpr.isStable && (alt1.widenExpr frozen_=:= alt2.widenExpr) + then + // alternatives are the same after following ExprTypes, pick one of them + // (prefer the one that is not a method, but that's arbitrary). + if alt1.widenExpr =:= alt2 then -1 else 1 + else if ownerScore == 1 then + if winsType1 || !winsType2 then 1 else 0 + else if ownerScore == -1 then + if winsType2 || !winsType1 then -1 else 0 + else if winsType1 then + if winsType2 then 0 else 1 else - if (winsType2) -1 else 0 + if winsType2 then -1 else 0 } if alt1.symbol.is(ConstructorProxy) && !alt2.symbol.is(ConstructorProxy) then -1 diff --git a/tests/pos/i18768.scala b/tests/pos/i18768.scala new file mode 100644 index 000000000000..67a5bd127200 --- /dev/null +++ b/tests/pos/i18768.scala @@ -0,0 +1,44 @@ +package minimized: + object Module: + object Exportee: + + opaque type Id = Long + + def apply(): Id = ??? + + extension (e: Id) + def updated: Id = ??? + + + object Client: + export Module.* + val x = Exportee().updated + +package original: + object Module: + trait EntityDef: + type Id + type Record + type Entity = (Id, Record) + + extension (e: Entity) + def updated: Entity = e + + case class Exportee() + object Exportee extends EntityDef: + opaque type Id = Long + type Record = Exportee + + def apply(id: Long): Entity = (id, Exportee()) + + object Client: + export Module.* + val x = Exportee(1L).updated + + + object ClientWorkingWithManualExport: + export Module.{Exportee as _, *} + type Exportee = Module.Exportee + val Exportee = Module.Exportee + + val x = Exportee(1L).updated