Skip to content

More precise type for typed patterns, less precise for literal patterns #8710

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
Apr 12, 2020

Conversation

smarter
Copy link
Member

@smarter smarter commented Apr 12, 2020

In x @ Nil, Nil is a stable identifier pattern and will be compiled
to an == test, so the type of x is unrelated to the type of Nil.
This was handled correctly before this commit, but the check to use the
moe restrictive patten typing was too wide and also included typed
patterns like x: Nil.type, even though such patterns compile to eq
tests and therefore it's safe to assume that x has type Nil.type.

Additionally, a literal pattern will also be compiled to an == test
and therefore should be less precisely typed, like a stable identifier
patterns.

In `x @ Nil`, `Nil` is a _stable identifier pattern_ and will be compiled
to an `==` test, so the type of `x` is unrelated to the type of `Nil`.
This was handled correctly before this commit, but the check to use the
moe restrictive patten typing was too wide and also included typed
patterns like `x: Nil.type`, even though such patterns compile to `eq`
tests and therefore it's safe to assume that `x` has type `Nil.type`.

Additionally, a _literal pattern_ will also be compiled to an `==` test
and therefore should be less precisely typed, like a stable identifier
patterns.
Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

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

LGTM

@smarter smarter merged commit bd1fff2 into scala:master Apr 12, 2020
@smarter smarter deleted the typed-patterns branch April 12, 2020 19:49
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.

2 participants