-
Notifications
You must be signed in to change notification settings - Fork 389
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
[annotator] support scala 3.4 irrefutable patterns in for-comprehension #SCL-22274 fixed #660
Conversation
def needsPatternMatchFilter(pattern: ScPattern): Boolean = | ||
!pattern.isIrrefutableFor(if (forDisplay) pattern.expectedType else None) | ||
def needsPatternMatchFilter(pattern: ScPattern): Boolean = { | ||
val hasSc3Case = pattern.isScala3OrSource3Enabled && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It currently works without this check, however, with Scala 3, when pattern starts with case
, compiler will require the right hand to have withFilter
.
I believe this check should stay for this reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like the check is required, but currently not covered with tests.
It will be more clear once comment is addressed
It doesn't address the case where type narrowing occurs (couldn't figure out how to detect type narrowing): for y :: ys <- List(List(1), List(2)) do println(y) IntelliJ will not produce an error for Scala 3.4, but compiler will produce this:
and Scala 3.0+ will produce the same but as a warning. |
Please see this part of our guidelines
Right now the commit message doesn't mention YT issues. |
import Message.Error | ||
|
||
override protected def supportedIn(version: ScalaVersion): Boolean = version >= LatestScalaVersions.Scala_3_0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the exact version Scala_3_3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean only to bump to 3.3 or change it to version == LatestScalaVersions.Scala_3_3
?
If the latter, why? These tests should pass for all Scala 3 versions (as of right now at least).
EDIT: I just realised there are some incorrect assumptions in the test cases. I'll restructure the tests and then let's take another round on the changes.
} | ||
|
||
class ForComprehensionIrrefutableTest_3_future extends ForComprehensionHighlightingTestBase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here as well, let's use the exact version Scala_3_3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, to ensure all the cases are covered, maybe let's inherit from ForComprehensionRefutableTest_3
and override needed tests
(same for Scala 3.4 tests)
!pattern.isIrrefutableFor(if (forDisplay) pattern.expectedType else None) | ||
def needsPatternMatchFilter(pattern: ScPattern): Boolean = { | ||
val hasSc3Case = pattern.isScala3OrSource3Enabled && | ||
pattern.prevSiblingNotWhitespace.exists(_.getText == ScalaModifier.CASE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As IntelliJ suggests, please replace _.getText == ScalaModifier.CASE
with _.textMatches(ScalaModifier.CASE)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed, though, I don't get that suggestion. Possibly, because I don't have access to plugin com.jetbrains.intellij.api.watcher
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right the inspection should work in internal mode.
https://github.com/JetBrains/intellij-scala/blob/7a050b30da86b846ca88fa92f51f875b7b805c1d/README.md#prerequisites
(optional but recommended)
Enable internal mode in IDEA to get access to helpful internal actions and debug information
Want me to force update first commit or just touch up the PR title and description? |
def needsPatternMatchFilter(pattern: ScPattern): Boolean = | ||
!pattern.isIrrefutableFor(if (forDisplay) pattern.expectedType else None) | ||
def needsPatternMatchFilter(pattern: ScPattern): Boolean = { | ||
val hasSc3Case = pattern.isScala3OrSource3Enabled && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is OrSource3Enabled
part needed in this check?
AFAIU the logic should be only about Scala 3 and not about Scala 2.
pattern.isInScala3File
should do.
Or even extract val features = pattern.features
and use features.isScala3
, features.hasSourceFutureFlag
Force push to your branch should be ok |
You can omit the "fixed" part and just mention the ticket.
Sounds like a good plan. |
…on #SCL-22274 fixed This fixes false missing withFilters error for irrefutable patterns in for comprehensions introduced with Scala 3.4 and Scala 3.0 + -source:future. Related #SCL-22468
Alright, all comments should be addressed now (including first commit messaging). Should I do something about it? |
Thanks for the contribution!
No, thanks. I will deal with it. |
This fixes false missing
withFilters
error for irrefutable patterns in for comprehensions introduced with Scala 3.4 and Scala 3.0 +-source:future
.Related #SCL-22468