Skip to content

improvement: Simplify match types when possible #23146

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

Merged
merged 1 commit into from
May 13, 2025

Conversation

tgodzik
Copy link
Contributor

@tgodzik tgodzik commented May 13, 2025

@tgodzik tgodzik requested a review from kasiaMarek May 13, 2025 11:38
s"""|toString(): String
|toArray: Array[Object]
|toIArray: IArray[Object]
|toList: List[Int]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

PReviously this was shown as a full match type

val returnType = tpe(gtpe.finalResultType)
val retType = gtpe.finalResultType
val simplified = if (retType.typeSymbol.isAliasType) retType else retType.deepDealiasAndSimplify
val returnType = tpe(simplified)
Copy link
Member

Choose a reason for hiding this comment

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

Won't simplified negatively impact union types?

def f(): Int | String = ???

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a test, it seems to work. I don't think it will simplify something it's unable to simplify more. Do you have another example that might highlight the issue?

Copy link
Member

Choose a reason for hiding this comment

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

It's fine then, I think it works as we'd like it to. 😄 I saw it does lub on OrType but it seems to still return an unchanged OrType, maybe it only collapses same cases.

Copy link
Member

@kasiaMarek kasiaMarek left a comment

Choose a reason for hiding this comment

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

LGTM

@tgodzik tgodzik merged commit e5a9355 into scala:main May 13, 2025
29 checks passed
@tgodzik tgodzik deleted the fix-match-long branch May 13, 2025 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Label should not contain long descriptions
2 participants