Skip to content

Pattern matching against enum case without parameters compiles without warnings #21618

Open
@lolgab

Description

@lolgab

Compiler version

3.5.0 (3.4.0+)
3.3.3 works correctly

Minimized code

enum Foo:
  case Bar(i: Int)
case class Container(foo: Foo) 

@main def main = Container(Foo.Bar(1)) match {
  case Container(Foo.Bar) => println("yes")
  case _ => println("no")
}

Output

Using Scala 3.5.0

no

Using Scala 3.3.3

[error] ./main.scala:8:18
[error] Found:    Foo.Bar.type
[error] Required: Foo
[error] pattern type is incompatible with expected type
[error]   case Container(Foo.Bar) => println("yes")
[error]                  ^^^^^^^
Error compiling project (Scala 3.3.3, JVM (11))
Compilation failed

Expectation

It should fail to compile since Container takes a Foo and I expect Foo.Bar to be of type Foo.Bar.type but not of type Foo.
Scala 3.3.3 does the right thing, but 3.5.0 doesn't.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions