-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Prevent Pattern Match Exhaustivity Warning for transparent
#4863
Comments
A transparent method can be defined in library A and used in library B; certain bugs in A will only be visible while compiling B. So there's still a point in exhaustivity warnings. So, can you point to any downside to these warnings? You can always add a fallback using // Peano naturals as in other examples, omitted
transparent def pred(n: Nat) = n match {
case S(m) => m
// we want to fail on pred(Z)! So either omit the case or make this explicit
case Z => compileError("Calling pred(Z) is illegal")
}
transparent def compileError(msg: String): Nothing =
... // XXX figure out how to implement this, or provide it ourselves |
I see your point. That makes sense. Is there a nice way currently to implement |
In scalac, you can have transparent def pred(n: Nat) = n match {
case S(m) => m
case Z =>
@compileTimeOnly("n cannot be Z") val res = ???
res
} I imagine that it could also rely on constant folding of strings to compose the message at compile-time, since the annotation is checked only after type-checking and macro/transparent expansion occur. |
That should be addressed by
Sorry for the ambiguity, I did mean "I don't know but we should have it one way or the other". |
@LPTK That annotation could be useful if the message can be treated as an error message that the compiler shows when it encounters it during transparent methods expansion. @Blaisorblade The |
I'm not sure I understand. When properly implemented (as in scalac), |
@LPTK Sorry what I meant to say that if that's what this annotation does then that's great! I was just not familiar with it. :) |
Is it possible to create a |
Hi, I believe that pattern match exhaustivity warnings should not be emitted for top-level pattern match statements in
transparent
methods, given that the pattern match is checked and expanded at compile-time anyway.I noticed these warnings are emitted when matching over a sealed trait/class in a transparent method body.
The text was updated successfully, but these errors were encountered: