Open scabug opened 9 years ago
Imported From: https://issues.scala-lang.org/browse/SI-9301?orig=1 Reporter: Erik Westra (eecolor) Affected Versions: 2.11.6
@Ichoran said: I agree that the logic is wrong. I think it's wrong because the type computation is hard to perform correctly, which is that you want A1 and A to intersect and be non-empty (unless A1 or A are Nothing). That is, you want the types to indicate that there's some hope to actually do something.
I'm not sure what the best fallback from that is, but I'm sure that insisting that A1 <: A, and then restricting the static type of the domain is wrong, since the original partial function might have perfectly well have handled some of the things in A - A1!
Unfortunately, these sorts of things are hard to change. I'm afraid you'll have to rely upon the workaround for a while.
Why isn't it, or "can't it be", A1 >: A
?
In the specific case of Akka's actors, the modern solution is moving to akka-actor-typed!
Because you can't pass a supertype to the original partial function. As the workaround shows you would need a ClassTag
. Maybe one could use union types in Dotty somehow.
The current definition is:
This prevents me from creating groups capturing sealed traits and chaining them:
I am using this pattern with actors to prevent myself from forgetting to implement handlers for messages.
A partial function should not get the most specific type. It should get the least specific type. After all, it has an
isDefinedAt
method.My current workaround: