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
- implement Contains Wart for List and Option #566
base: master
Are you sure you want to change the base?
Conversation
package warts | ||
|
||
object Contains extends WartTraverser { | ||
private[warts] def message: String = "Don't use List or Option `contains` method because is not typesafe" |
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.
actually they are type safe, just not very useful.
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 is possible to implement something like List(1).contains(true)
without any warning about it
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 agree a warning would be a good thing - my issue is with the wording, because technically it is type safe: you'll never get a ClassCastException
at run time, the result is correct, and there are even legitimate use cases for this behaviour. just not very many.
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 agree, can you suggest better wording for the warning?
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.
sorry, i'm not even sure i'd want to disable these functions without some more useful replacement - which if it existed, should probably be suggested in the message
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.
contains
in Lists and Options is type unsafe it is possible to implement List(1).contains("1"). Use type-safe implementation for example from cats List.contains_
something like that?
`contains` in Lists and Options is type unsafe it is possible to implement List(1).contains("1"). Use type-safe implementation for example from cats `List.contains_` | ||
````scala | ||
// Won't compile: List.contains is disabled | ||
List(1).contains(1) |
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.
but this is the useful case, isn't it? it might make sense to only disable them for un-related types...
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.
that is generally a bad idea to use native contains , my opinion is that always something like cats.contains_ should be used to be safe
FYI 37e9823 |
Current situation:
List.contains
andOption.contains
operations are not type-safe, which means it is possible to compileList(1).contains("1")
this wart disables contains in List's and Options
it was also suggested here - #48