-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 against enum
case without parameters compiles without warnings
#21618
Comments
I think these kinds of checks are now covered by |
BTW, the error is still raised in 3.3.4-RC4.
@bracevac it's true [warn] ./repro.scala:7:18
[warn] Implausible pattern:
[warn] Foo.Bar could match selector of type Foo
[warn] only if there is an `equals` method identifying elements of the two types.
[warn] case Container(Foo.Bar) => println("yes")
[warn] ^^^^^^^ So at first glance it looks like a regression, but indeed it seems these checks have been moved behind a linting flag and the errors downgraded to warnings. I wonder if it wouldn't make sense to be able to identify them as errors (I'd personally expect them to be errors). |
If I add an enum Foo:
def equals(x: Bar, y: Bar) = true
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") I still get a warning. So I think should not be an error, because now the program would print "yes". The problem is the compiler does not know what the equals method, if one is given, does. So it has to argue on the basis of plausibility, and such guesses should in general not be errors. |
@odersky ah, I see, thanks for explaining. |
One thing I don't understand is the role of the |
There is no way |
Yes but the example can easily be changed so that's no longer true. |
@odersky that would be a separate issue |
What do you mean? How is it distinct from this issue? |
Compiler version
3.5.0
(3.4.0
+)3.3.3
works correctlyMinimized code
Output
Using Scala
3.5.0
Using Scala
3.3.3
Expectation
It should fail to compile since
Container
takes aFoo
and I expectFoo.Bar
to be of typeFoo.Bar.type
but not of typeFoo
.Scala
3.3.3
does the right thing, but3.5.0
doesn't.The text was updated successfully, but these errors were encountered: