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

Don't optimize explicitly written isInstanceOf tests away. #14715

Merged
merged 4 commits into from Mar 21, 2022

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Mar 19, 2022

Do it only for tests generated during pattern matching.

Fixes #14705.

See the issue for a rationale of the change.

Do it only for tests generated during pattern matching.

Fixes scala#14707.

See the issue for a rationale of the change.
@odersky
Copy link
Contributor Author

odersky commented Mar 19, 2022

Alternative for #14709.

@odersky
Copy link
Contributor Author

odersky commented Mar 20, 2022

This was quite a rabbit hole.

First, I fixed the problem that even explicitly written isInstanceOf tests get optimized away. Then, a test in TreeChecker broke since it was an ill-formed test against Nothing that was optimized away previously. But the error message did not make sense. So I fixed the error message and then I fixed that test. Then a transform in TailRec broke. It generated illegal code that was supposed to be checked by the TreeChecker test, but wasn't since the test was optimized away. So in the end I had to fix TailRec, TreeChecker and TypeTestCasts.

@odersky odersky requested a review from sjrd March 20, 2022 13:23
@odersky odersky self-assigned this Mar 20, 2022
@odersky
Copy link
Contributor Author

odersky commented Mar 20, 2022

Closed in favor of #14715

@odersky odersky closed this Mar 20, 2022
@som-snytt
Copy link
Contributor

Closed in favor of alternative #14709 I admit I clicked the self-link, maybe more than once.

@odersky
Copy link
Contributor Author

odersky commented Mar 21, 2022

Oops, I meant to close #14709 instead.

Copy link
Member

@dwijnand dwijnand left a comment

Choose a reason for hiding this comment

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

Seb to review, but LGTM

Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

Other than some changes that are apparently in the wrong commit (see below), LGTM.

Comment on lines -2180 to +2182
class TypeTestAlwaysSucceeds(scrutTp: Type, testTp: Type)(using Context) extends SyntaxMsg(TypeTestAlwaysSucceedsID) {
def msg = {
val addendum =
if (scrutTp != testTp) s" is a subtype of ${testTp.show}"
else " is the same as the tested type"
s"The highlighted type test will always succeed since the scrutinee type ${scrutTp.show}" + addendum
}
class TypeTestAlwaysDiverges(scrutTp: Type, testTp: Type)(using Context) extends SyntaxMsg(TypeTestAlwaysDivergesID) {
def msg =
s"This type test will never return a result since the scrutinee type ${scrutTp.show} does not contain any value."
Copy link
Member

Choose a reason for hiding this comment

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

These changes don't seem to belong to this commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are actually linked to the changes in TypeTestsCasts. We had an error TypeTestAlwaysSucceeds before but now we have a TypeTestAlwaysDiverges instead.

@odersky odersky merged commit 0b4e96c into scala:main Mar 21, 2022
@odersky odersky deleted the fix-14705-v2 branch March 21, 2022 17:04
@Kordyjan Kordyjan added this to the 3.1.3 milestone Aug 1, 2023
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.

Pattern matching on unchecked generic types (with isInstanceOf guard) does not work correctly
5 participants