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

Nil and LinearSeq cannot be compared #21392

Closed
Bersier opened this issue Aug 15, 2024 · 4 comments · Fixed by #21504
Closed

Nil and LinearSeq cannot be compared #21392

Bersier opened this issue Aug 15, 2024 · 4 comments · Fixed by #21504
Labels
Milestone

Comments

@Bersier
Copy link
Contributor

Bersier commented Aug 15, 2024

Compiler version

3.5.1-RC2

Minimized code

import scala.collection.LinearSeq

def foo[T](a: LinearSeq[T]) = a match
  case Nil => -1
  case head +: tail => head

Compiler options

 -language:strictEquality
 -Yexplicit-nulls

Compiler output

Values of types object Nil and LinearSeq[T] cannot be compared with == or !=.

Expectation

No compile-error

Note: the addition of CanEqual givens between Nil.type and LinearSeq does not help.

@Bersier Bersier added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Aug 15, 2024
@dwijnand dwijnand added area:strictEquality scala.language.strictEquality and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Aug 15, 2024
@noti0na1
Copy link
Member

It is weird that the error only happens if both flags are enabled.

@goshacodes
Copy link

goshacodes commented Aug 28, 2024

Hello, one more example. This bug is really blocking usage of strictEquality.
Versions: 3.3.3, 3.5.0

Example

enum Foo:
  case Bar
  case Baz(x: String)


def foo(a: Foo) = a match
  case Foo.Bar => -1
  case _ => 0

Output

Values of types Playground.Foo and Playground.Foo cannot be compared with == or !=

@noti0na1
Copy link
Member

enum Foo:
  case Bar
  case Baz(x: String)


def foo(a: Foo) = a match
  case Foo.Bar => -1
  case _ => 0

Output

Values of types Playground.Foo and Playground.Foo cannot be compared with == or !=

For this example, the error is not related to explicit nulls, and you need to add derives CanEqual to Foo.

@goshacodes
Copy link

enum Foo:
  case Bar
  case Baz(x: String)


def foo(a: Foo) = a match
  case Foo.Bar => -1
  case _ => 0

Output

Values of types Playground.Foo and Playground.Foo cannot be compared with == or !=

For this example, the error is not related to explicit nulls, and you need to add derives CanEqual to Foo.

Hmm, ok) Thank you.

@WojciechMazur WojciechMazur added this to the 3.6.0 milestone Oct 8, 2024
WojciechMazur added a commit that referenced this issue Dec 4, 2024
…plicit nulls" to LTS (#22113)

Backports #21504 to the 3.3.5.

PR submitted by the release tooling.
[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants