-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Improved errors using type reference targets #25115
Conversation
c196ddf
to
33b1e3a
Compare
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.
Good improvement, and we can keep iterating on it. We may want to unify the two loops over the union members we do here so we avoid iterating the list twice, but that can be done in the future if its needed.
if ((source as ObjectType).objectFlags & (target as ObjectType).objectFlags & ObjectFlags.Reference) { | ||
return (source as TypeReference).target === (target as TypeReference).target; | ||
} | ||
if ((source as ObjectType).objectFlags & (target as ObjectType).objectFlags & ObjectFlags.Anonymous) { |
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.
Use getObjectFlags
instead of (source as ObjectType).objectFlags
It's odd that only one baseline changed besides the new test, and the change is not an improvement (although not much of a regression since it was quite confusing already). Does this change the user test or RWC test baselines? If so, do those error message look better? |
It's just selecting the first type instead of the last, since both are references to the tuple type. |
Oops, what I really meant to say was that it's odd that only one baseline changed. And also the one change isn't an improvement, which isn't odd because it's hard to change things without breaking something. Together, the two things make me wonder whether any more changes exist so that we can know whether they are improvements or not. |
I agree; I was pretty disappointed to see the lack of improvement in the existing test suite. Maybe we'll see improvements in the RWC errors though. |
Fixes #24776
This pull request should improve error messages when assigning type references to union types when a target type contains a type reference whose target type matches the source's.
As an example,
Previously we would report
Notice that we try to use
B<Baz>
to explain the incompatibility. Intuitively, we'd assume thatA<Bar>
is probably what the user wanted to assign to.With this change, we report a more relevant error:
Currently I'm trying to get this to also work for anonymous types which have a well-associated alias type, however, I might need help there (@weswigham @sandersn).As future work, we can
Derived
to aBase<Foo>