-
Notifications
You must be signed in to change notification settings - Fork 1.1k
False unreachable warning #1917
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
Comments
I think I suggested somewhere that we simply disallow anonymous classes that directly extend sealed traits, since they make it impossible to satisfy exhaustivity checks without adding default cases and can easily be rewritten to something like |
Seems I missed the notification. Anonymous class is a known issue. Here is the PR note we have before:
|
In case we want to support anonymous-classes, we can also lazily auto-generate a super-class |
Looking at https://github.com/lampepfl/dotty/pull/1918/files I don't see how you could get nice exhaustiveness messages from something like |
Yes, I think we need to specialize the exhaustiveness checker for enums. We
cannot replace
case object Red extends Color
by
val Red: Color = new ...
because the widened types are different (Color, respectively the module
class of Red).
- Martin
…On Fri, Feb 3, 2017 at 11:25 AM, Guillaume Martres ***@***.*** > wrote:
I think we need anonymous classes in sealed traits for a good treatment of
enums. /cc @retronym <https://github.com/retronym> who suggested this to
me.
Looking at https://github.com/lampepfl/dotty/pull/1918/files I don't see
how you could get nice exhaustiveness messages from something like val
Red: Color = $new(0, "Red") without special-casing the exhaustiveness
checker for enums. Couldn't you just use case object instead, with the
twist that instead of generating a companion val val Red: Red$ = new
Red$() it would be val Red: Color = new Red$() ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1917 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAwlViFMwvjA2PKGFx4fGXCGBCgS1l7yks5rYnP2gaJpZM4LyNC->
.
{"api_version":"1.0","publisher":{"api_key":"
05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":
{"external_key":"github/lampepfl/dotty","title":"
lampepfl/dotty","subtitle":"GitHub repository","main_image_url":"
https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-
11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://
cloud.githubusercontent.com/assets/143418/15842166/
7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in
GitHub","url":"https://github.com/lampepfl/dotty"}},"
***@***.*** in #1917:
\u003e I think we need anonymous classes in sealed traits for a good
treatment of enums. /cc @retronym who suggested this to me.\r\n\r\nLooking
at https://github.com/lampepfl/dotty/pull/1918/files I don't see how you
could get nice exhaustiveness messages from something like `val Red: Color
= $new(0, \"Red\")` without special-casing the exhaustiveness checker for
enums. Couldn't you just use `case object` instead, with the twist that
instead of generating a companion val `val Red: Red$ = new Red$()` it would
be `val Red: Color = new Red$()` ?"}],"action":{"name":"View Issue","url":"
#1917 (comment)"}}}
--
Prof. Martin Odersky
LAMP/IC, EPFL
|
If the purpose to support exhaustivity check of the new enum-style ADTs, then there is an easy solution. We only need to pass the list of children from parser to the exhaustivity checker (some trick in type checking required to transform the children list from syntactic to symbols). For the enum |
I'd prefer if it was done in a separate Mini-Phase, that would be in block with |
If I understand correctly, you mean to gather the children list in a mini-phase after typer? I assume the enum-style ADTs will get desugared before type checking. If we don't keep the children list from the parser, we lose some information in the syntax and would need a lot of resugaring efforts to restore the children information which is available in the syntax. |
Subclassing relationship will definitely not be lost, and that's the only thing, I think, you need here. |
For the enum https://github.com/lampepfl/dotty/pull/1918/files#diff-07e5eb314978ffa9168b31a3c887de9dR15 |
Fixed in #2197. |
the opposite of a false unreachable warning is the failure to emit an non-exhaustive-match warning. the discussants above may know this already, but for the record, note that Scala 2.12 correctly issues a warning in this case:
but Dotty still does not. should I open a new ticket on it? |
@SethTisue Good timing: #5396 :) |
Given:
we get:
The warning should not be issued, since the line is reachable.
The text was updated successfully, but these errors were encountered: