Skip to content
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

Pattern Matching inconsistency #22064

Open
CyrilFMoser opened this issue Dec 2, 2024 · 1 comment
Open

Pattern Matching inconsistency #22064

CyrilFMoser opened this issue Dec 2, 2024 · 1 comment
Labels
area:pattern-matching area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug

Comments

@CyrilFMoser
Copy link

CyrilFMoser commented Dec 2, 2024

Compiler version

3.6.1

Minimized code

This does not issue a pattern match exhaustivity warning:

sealed trait T_A[B]
case class CC_C(a: Int, b: T_A[Int]) extends T_A[Char]

val v_a: T_A[Char] = null
val v_b: Int = v_a match{
  case CC_C(0, _) => 0 
}

But this does:

sealed trait T_A
sealed trait T_B
case class CC_A(a: Int, b: T_B) extends T_A

val v_a: T_A = null
val v_b: Int = v_a match{
  case CC_A(0,_) => 0 
}

Expectation

They should behave the same. The issue generally appears when matching against traits that don't have any case classes extending them, given certain generics. (Here T[Int]). But it does not appear when a trait simply has no case classes extending them, regardless of generics (T_B).

My guess is that this is related to the fact that the pattern matcher does not enforce covering nulls explicitly, so if the only way to create a case class is with a null it thinks that this case class could never be constructed (first program) and therefore also does not need to match against it

I believe my previous bug reports had this same issue at the root, and the fix in #21000 (which to my knowledge should be included in 3.6.1?) did not resolve this issue.

@CyrilFMoser CyrilFMoser added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 2, 2024
@noti0na1
Copy link
Member

noti0na1 commented Dec 2, 2024

Could be related to the discussion at #21934

@dwijnand dwijnand removed the stat:needs triage Every issue needs to have an "area" and "itype" label label Dec 2, 2024
@Gedochao Gedochao added area:reporting Error reporting including formatting, implicit suggestions, etc area:pattern-matching labels Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:pattern-matching area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug
Projects
None yet
Development

No branches or pull requests

4 participants