maybe I can open a feature request on the kotlin p...
# announcements
g
maybe I can open a feature request on the kotlin plugin to flag any set operators on
Collection<A> op Collection<B> -> Collection<Serializable>
as suspicious?
n
This is just a result of inheritance and covariance though, isn't it
I don't think there's anything unexpected happening here
Ah, you're just asking for a warning
g
yeah exactly, its as intended, its just unfortunate
n
The thing, is, as soon as you use the result of that expression for anything, you'll almost certainly get a compiler error, no?
g
except if you use the monadic set combinators as I was
n
Hah, well 🙂
It may have delayed it, but I would still expect, that eventually, you'll do something where you actually expect to have, at least, a Collection<String>
g
that particular code more-or-less translates to
Copy code
if((a - b - c).isEmpty()) { return validationFailure() }
n
Ah, I see
A great example
I wonder if there is any way to keep covariance useful, and avoid situations like these
g
I'm wondering how common it is to have these set operators yield a result of
Set<Any>
or similar and still be useful
actually
n
Well, this sort of thing is going to apply to pretty much all of the read-only binary collection operations
g
right but my brain isnt big enough for all of them
but subtraction has interesting implications for equality
n
Collection<Any> is probably almost always wrong, but I guess, where do you draw the line? The further "down" the type is the more likely it is to be correct.
g
if we just think about minus, then we could make some condition like: given expr = Set<A> - Set<B> then: A and B must share an implementation of equals
n
Yes, subtraction is especially bad.
g
im guessing that writing analysis to "find the least common ancestor implementation of equals on types A and B" is not a cheap question for the kotlin plugin to ask
n
Kotlin will already error out on comparing 2 unrelated types though
So now I'm wondering how this compiles
I guess, things like Set internallyuse .equals, and not ==
?
g
depends on the set implemnetation of course but
AbstractSet
does use deep equality
Treeset's require use of a comparator ofc makes this more complex
n
== and .equals are both deep equality
Ugh, == is the same as .equals for non primitive types, I didn't realize that
So things like
listOf(5) == setOf(20)
compile 😞
hmm, actually, just not sure anymore, need to check this out again later