Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect case where two alternatives are the same after widening ExprTypes #18787

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1780,14 +1780,21 @@ 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 =:= alt2.widenExpr
&& alt1.widenExpr.isStable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check is isStable first, for performance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good idea.

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
Expand Down
14 changes: 14 additions & 0 deletions tests/pos/i18768.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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
Loading