-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Possible problems with typed adapters #31393
Comments
What if it's not matched with the predicate? I think IDEA and scalac do some checks too. |
Since |
It would be nice to sort the adapters with most specific first. Not sure if that can be done? |
One could probably define an // only mentally compiled...
new Ordering[Class[_]] {
def compare(x: Class[_], y: Class[_]): Int = {
val xAssignableToY = y.isAssignableFrom(x)
val yAssignableToX = x.isAssignableFrom(y)
(xAssignableToY, yAssignableToX) match {
case (true, true) => 0 // same class
case (false, true) => 1 // x is a supertype of y
case (true, false) => -1 // y is a supertype of x
case (false, false) => 0 // arbitrary: no relation between the class objects
}
}
} Then we could maybe use a That said, that approach is a behavior change: keeping the same structure but removing elements based on assignability wouldn't change behavior but save a bit of memory. |
refs: #22849 too |
Noticed by @leviramsey :
Message adapters are kept in a list which is prepended to after filtering out any created adapter for the exact same incoming message type.
When applying the adapters, it is traversed from most recent and backwards, checking if the incoming message is assignable from the class for each adapter.
This means you can register multiple adapters from the same class hierarchy and get different behavior based on the order the adapters were spawned in, so these two snippets will adapt differently:
Maybe this is fine, if you create many adapters which match further and further up in the class hierarchy, that will keep a bunch of adapters around that will never be used. But on the other hand we recommend to not create a ton of adapters in the docs.
We could perhaps look for earlier adapters assignable from the latest to filter such out as well?
Not sure if there is some more tricky consequence of this that I'm not seeing?
The text was updated successfully, but these errors were encountered: