You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
traitAtraitBdeftest(x: A|B) = x matchcase_: A=> println("A")
casenull=> println("null")
case_: B=> println("B")
case _ => println("default") // unreachable
Output
The last case is reported as unreachable except for null, and suggested to be rewritten to case null =>.
-- [E121] PatternMatchWarning:Stest.scala:1240:7----------------------------1240|case _ => println("default")
|^|Unreachablecase except fornull (ifthis is intentional, consider writing casenull=> instead).
1 warning found
If we replace the wildcard to literal null in the last case, it will be reported as unreachable directly.
-- [E030] MatchcaseUnreachableWarning:Stest.scala:1240:7-------------------1240|casenull=> println("default")
|^^^^|Unreachablecase1 warning found
Expectation
The last redundant wildcard case should be reported as unreachable.
Issue
In checkReachability:
if pat !=EmptyTree// rethrow case of catch uses EmptyTree&&!pat.symbol.isAllOf(SyntheticCase, butNot=Method) // ExpandSAMs default cases use SyntheticCase&& isSubspace(covered, prev)
then {
valnullOnly= isNullable && i == len -1&& isWildcardArg(pat)
valmsg=if nullOnly thenMatchCaseOnlyNullWarning() elseMatchCaseUnreachable()
report.warning(msg, pat.srcPos)
}
The text was updated successfully, but these errors were encountered:
Although this issue is produced without explicit nulls, I still add the nullability label because we need to be careful with the behaviour in explicit nulls as well.
deftest(s: String|Null) = s match// s: String also has the same issuecase ss => println(1)
case _ => println(2) // get warning for unreachable except for null// but it is unreachable even for null// both print 1
test("")
test(null)
Compiler version
3.6.0-RC1-bin-SNAPSHOT-nonbootstrapped-git-6ceaab5
Minimized code
Output
The last case is reported as unreachable except for null, and suggested to be rewritten to
case null =>
.If we replace the wildcard to literal
null
in the last case, it will be reported as unreachable directly.Expectation
The last redundant wildcard case should be reported as unreachable.
Issue
In
checkReachability
:The text was updated successfully, but these errors were encountered: