-
Notifications
You must be signed in to change notification settings - Fork 3.1k
SI-8731 warning if @switch is ignored #4016
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
Conversation
Review by @gkossakowski |
} | ||
val requireSwitch = hasSwitchAnnotation && lengthMax3(casesNoSubstOnly) > 2 | ||
if (hasSwitchAnnotation && !requireSwitch) | ||
reporter.warning(scrut.pos, "ignoring @switch, warnings are only issued for matches with more than two cases") |
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.
shouldn't it be for matches with two or less cases
?
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.
no, but maybe i have to come up with a clearer wording.
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.
maybe :)
i understood this as if you have a pm with 1 | 2 cases and switch annotation, than this warning is issued, as for 2 or less cases switch is ignored.
cc @adriaanm |
// matches with two or fewer cases need not apply for switchiness (if-then-else will do) | ||
val requireSwitch = treeInfo.isSwitchAnnotation(tpt.tpe) && casesNoSubstOnly.lengthCompare(2) > 0 | ||
// `case 1 | 2` is considered as two cases. | ||
def lengthMax3[T](l: List[T]): Int = l match { |
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.
Maybe wrap the lengthMax3(casesNoSubstOnly) > 2
in def exceedsTwoCasesOrAlts
(to explain what kind of 'length' we're measuring), which contains lengthMax3
as a local method?
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.
sure, thanks. so in general you agree with the additional warning?
I think the warning makes sense to introduce. I agree with @adriaanm's suggestion to clarify the condition as expressed in code. |
OK. I'll get it fixed up later today. |
For matches with two or fewer cases, @switch is ignored. This should not happen silently.
created a method |
LGTM |
SI-8731 warning if @switch is ignored
For matches with two or fewer cases, @switch is ignored. This should
not happen silently.