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

ClassCastException from simple use of pattern matching #14587

Closed
oscar-broman opened this issue Feb 28, 2022 · 1 comment · Fixed by #14590
Closed

ClassCastException from simple use of pattern matching #14587

oscar-broman opened this issue Feb 28, 2022 · 1 comment · Fixed by #14590
Assignees
Labels
area:pattern-matching itype:bug prio:blocker regression This worked in a previous version but doesn't anymore
Milestone

Comments

@oscar-broman
Copy link

Compiler version

3.1.3-RC1-bin-20220226-8922c88-NIGHTLY

Works in 3.1.2-RC1 and 3.1.0

Minimized code

def test(foo: String): Unit = {
  // Does not crash if the type is written explicitly as: Option[(Option[Int], String)]
  val bar = {
    if (foo.isEmpty) Some((Some(1), ""))
    else Some((None, ""))
  }

  bar.foreach {
    case (Some(_), "") =>
    case _ =>
  }
}

test("") // works
test("a")

Output

Exception in thread "main" java.lang.ClassCastException: class scala.None$ cannot be cast to class scala.Some (scala.None$ and scala.Some are in unnamed module of loader 'app')

Expectation


@oscar-broman oscar-broman added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 28, 2022
@smarter smarter added area:pattern-matching prio:blocker and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 28, 2022
@smarter smarter modified the milestones: 3.1.2, 3.2.0-RC1 Feb 28, 2022
@smarter
Copy link
Member

smarter commented Feb 28, 2022

Regressed in #14296

@dwijnand dwijnand added the regression This worked in a previous version but doesn't anymore label Feb 28, 2022
@smarter smarter modified the milestones: 3.2.0-RC1, 3.1.3-RC1 Mar 7, 2022
@Kordyjan Kordyjan modified the milestones: 3.1.3-RC1, 3.1.3 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:pattern-matching itype:bug prio:blocker regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants