Skip to content

Spurious unreachable case warning #16123

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

Closed
Bersier opened this issue Sep 29, 2022 · 10 comments · Fixed by #16179
Closed

Spurious unreachable case warning #16123

Bersier opened this issue Sep 29, 2022 · 10 comments · Fixed by #16179

Comments

@Bersier
Copy link
Contributor

Bersier commented Sep 29, 2022

Compiler version

3.2.0

Minimized code

sealed trait Nat
case class Zero() extends Nat
case class Succ[N <: Nat](n: N) extends Nat

def foo(n: Nat): Int = n match
  case Zero() => 0
  case Succ(Zero()) => 1
  case _ => 2 // warning for this line

foo(Succ(Succ(Zero()))) // evaluates to 2

Compiler warning

Unreachable case except for null (if this is intentional, consider writing case null => instead).

Expectation

No warning

@Bersier Bersier added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 29, 2022
@KacperFKorban KacperFKorban added area:pattern-matching and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 30, 2022
@dwijnand dwijnand self-assigned this Sep 30, 2022
@strelec
Copy link

strelec commented Oct 9, 2022

I has a similar issue in #15661

@tusharmath
Copy link

@tusharmath
Copy link

I am still facing this issue in 3.2.1 Has the fix not been released yet?

@KacperFKorban
Copy link
Member

The fix will be released in 3.2.2. It is currently included in 3.2.2-RC1 pre-release.

@tusharmath
Copy link

I tried again on 3.2.2-RC1 and am observing the same error.

@KacperFKorban
Copy link
Member

@tusharmath Which snippet are you running? The one from the issue description works correctly in 3.2.2-RC1 for me.

@tusharmath
Copy link

I think in my case it's a valid warning :D

@tusharmath
Copy link

@KacperFKorban
Copy link
Member

@tusharmath If you think that the warning in zio-schema is wrong, then could you create a new issue for it? (this would mean that it is caused by a different bug)

@tusharmath
Copy link

Created a small repro — #16379

dwijnand added a commit to dwijnand/scala3 that referenced this issue Dec 14, 2022
Not doing so, in a context where GADT inferrence is enabled, such as in
TypeOps.refineUsingParent, leads to false inferrences.

Doing so, and removing the previous fix for scala#15967, fixes the regression
in scala#16339, and keeps scala#15967 as well as scala#16123 (which is somewhat
related) fixed.
little-inferno pushed a commit to little-inferno/dotty that referenced this issue Jan 25, 2023
Not doing so, in a context where GADT inferrence is enabled, such as in
TypeOps.refineUsingParent, leads to false inferrences.

Doing so, and removing the previous fix for scala#15967, fixes the regression
in scala#16339, and keeps scala#15967 as well as scala#16123 (which is somewhat
related) fixed.
@Kordyjan Kordyjan added this to the 3.2.2 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants