-
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
Add CanEqual typeclass instance for Seq to match Nil case #13265
Add CanEqual typeclass instance for Seq to match Nil case #13265
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Would be nice to tweak the comments, but this shouldn't slip to 3.2.0 on that basis!
4931e71
to
ede2820
Compare
@dwijnand I've rebased the upstream mater and updated the commit as suggested. Thank you! |
given canEqualSeq[T, U](using eq: CanEqual[T, U]): CanEqual[Seq[T], Seq[U]] = derived | ||
given canEqualSeqs[T, U](using eq: CanEqual[T, U]): CanEqual[Seq[T], Seq[U]] = derived | ||
given canEqualSeq[T](using eq: CanEqual[T, T]): CanEqual[Seq[T], Seq[T]] = derived // for `case Nil` in pattern matching |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why the original given isn't enough to match Nil /cc @odersky
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the same logic as the Option/Either PR, you get:
case Nil =>
^^^
Values of types object scala.collection.immutable.Nil and List[Int] cannot be compared with == or !=.
I found:
CanEqual.canEqualSeq[Nothing, Int](/* missing */summon[CanEqual[Nothing, Int]])
But no implicit values were found that match type CanEqual[Nothing, Int].
@kevin-lee could you rebase this PR on master? We aim merge it for 3.1 |
@nicolasstucki Sure, I will do it soon. |
ede2820
to
665df86
Compare
@nicolasstucki Done! |
665df86
to
32a99fd
Compare
and done again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to add a comment why the new method is needed to the code. It is explained in the comments to the PR.
Add
CanEqual
instance forSeq
to matchNil
case.This PR solves the similar issue as what #12419 solves, but it's for pattern matching on
List
.With
-language:strictEquality
compiler option orimport scala.language.strictEquality
, the following case doesn't compilewith this compile-time error
This PR solves it.