-
Notifications
You must be signed in to change notification settings - Fork 12.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
Improve EPC for unions with multiple discriminants #32711
Conversation
051c748
to
a67c3cc
Compare
A: yes. |
} | ||
if (candidates) { | ||
let matchID: string | false | undefined; | ||
candidates.forEach((value, id) => { |
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.
A comment explaining what criteria this is filtering/selecting on would be useful. I think it's that it returns the first type which matches all discriminant properties (out of multiple which may match), but some text expressing that would be nice.
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.
Will do. If there are multiple valid matches it fails rather than picking the first. I did this to avoid situations where the order of the union influenced whether you got an error, sometimes incorrectly. (I think it was a case where some constituents were technically subtypes of another, but the union was unreduced).
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.
@weswigham Done. In the case where there are multiple candidates we could return a new union of just those candidates, but I'm not sure of the error message and perf consequences---if you want me to experiment with that approach let me know.
Thanks. What I've written feels kind of messy and could be cleaned up, but I hope the algorithm is on the right lines. |
a67c3cc
to
93de3ef
Compare
Sooooo, I also fixed this bug yesterday, in a different PR, while working on a different bug. The algorithms are almost the same, but I feel like my solution is easier to read:
@jack-williams would you mind taking a look? I'll merge your commit in order to get your test and make sure you get attribution for this fix as well. (Thanks @weswigham for pointing this out to me.) |
Fixes #32657
Q: Do I need to explicitly coerce map keys to string like:
candidates.set("" + type.id, 1);
?