Skip to content
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

Set symbol on union that is returned from getSpreadType #18965

Merged
merged 4 commits into from
Oct 11, 2017

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Oct 5, 2017

Fixes #16694

Previously, it was only set on a top-level type resulting from getSpreadType, and only if that top-level type was an object type. Now checkObjectLiteral uses forEachType to set the symbol on every object type in the union as well, if getSpreadType returns a union.

Previously, it was only set on the top-level type, and only if that
top-level type was an object type. Now it uses `forEachType` to set the
symbol on every object type in the union as well, if `getSpreadType`
returns a union.
Also tighten up the existing test code in the file.
@sandersn sandersn requested review from a user and weswigham October 9, 2017 18:14
t.flags |= propagatedFlags;
t.flags |= TypeFlags.FreshLiteral;
(t as ObjectType).objectFlags |= ObjectFlags.ObjectLiteral;
t.symbol = node.symbol;
Copy link
Member

@weswigham weswigham Oct 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this trample over the existing symbol on any object types spread (should one be present)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we instead pass this symbol to getSpreadType and avoid the mutation after creating the type..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weswigham In its current state getSpreadType + the emptyObjectType check above will never trample an existing type. However, @mhegazy's idea is much less error-prone for future changes. Right now, getSpreadType is only called from places that have a symbol on hand anyway, since it's not a real type operator like it was planned to be.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. It caused some churn in the ad-hoc JSX code, but it's probably worth it for the readability in checkObjectLiteral.

Previously, getSpreadType didn't set any flags and relied on its callers
to do so. This was error-prone because getSpreadType often returns
non-fresh types.
@sandersn sandersn merged commit 461e29b into master Oct 11, 2017
@sandersn sandersn deleted the set-symbol-on-union-of-spreads branch October 11, 2017 20:25
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants