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

inconsistency between "non-sensible equals warning" and stable identifier pattern #7211

Open
scabug opened this issue Mar 3, 2013 · 3 comments
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) patmat
Milestone

Comments

@scabug
Copy link

scabug commented Mar 3, 2013

scala> class C; class D
defined class C
defined class D

scala> val c = new C
c: C = C@4acdd9ba

scala> val d = new D
d: D = D@1ee8d9a5

scala> c == d
<console>:12: warning: C and D are unrelated: they will most likely never compare equal
              c == d
                ^
res14: Boolean = false

scala> val c = new C
c: C = C@462d62d9

scala> (new D) match { case `c` => true; case _ => false }
res10: Boolean = false
@scabug
Copy link
Author

scabug commented Mar 3, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7211?orig=1
Reporter: @retronym
Affected Versions: 2.10.0
See #5897

@SethTisue
Copy link
Member

Scala 3 doesn't warn on c == d, but it rejects the pattern match outright:

1 |(new D) match { case `c` => true; case _ => false }
  |                     ^^^
  |                     Found:    (c : C)
  |                     Required: D
  |                     pattern type is incompatible with expected type

I'm going to chalk that up as a "fixed in Scala 3"

@SethTisue SethTisue added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Feb 1, 2023
@som-snytt
Copy link

I ran out of steam trying to pin down when dotty gets it correct. Actually I wanted to go out for a run in the sun over an hour ago. I assume it's related to the linked ticket 7655, at least in spirit.

Welcome to Scala 3.2.2 (19, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> class C; object C extends C; class D extends C; object D extends D; val c = C(); val d = D()
// defined class C
// defined object C
// defined class D
// defined object D
val c: C = C@61911947
val d: D = D@640c216b

scala> D() match { case `c` => }
scala.MatchError: rs$line$1$D@44485db (of class rs$line$1$D)
  ... 33 elided

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) patmat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants