Skip to content

Fixed parenthesized array literal expressions spread in calls not being tupleized #54623

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

Merged

Conversation

Andarist
Copy link
Contributor

No description provided.

function checkArrayLiteral(node: ArrayLiteralExpression, checkMode: CheckMode | undefined, forceTuple: boolean | undefined): Type {
const elements = node.elements;
const elementCount = elements.length;
const elementTypes: Type[] = [];
const elementFlags: ElementFlags[] = [];
pushCachedContextualType(node);
const inDestructuringPattern = isAssignmentTarget(node);
const isSpreadIntoCallOrNew = isSpreadElement(node.parent) && isCallOrNewExpression(node.parent.parent);
const inConstContext = isSpreadIntoCallOrNew || isConstContext(node);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While reading the source code today I noticed that isSpreadIntoCallOrNew here (as part of inConstContext).

I think it was semantically incorrect (and I added it here). It didn't exactly create any issues because isConstContext here is mainly used to decide if the checked type should be readonly or not.

Since I removed part of the condition we can now observe removal of the readonly modifier from some snapshot tests. I think it's fine... or at least, I wasn't yet able to prove that those tuples should be readonly. Even in actual const contexts etc a mutable array is still fine. Even if it turns out that the readonly modifier is needed for some case, I think that it should be added independently, based on isSpreadIntoCallOrNew.

As a bonus, I noticed that parenthesized expressions were not handled here so I improved this.

Copy link
Member

Choose a reason for hiding this comment

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

The changed baselines that didn’t strictly need to change make this hard to approve. I’d rather not find out that the readonly was important in an untested edge case because of a regression.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I split this into 2 PRs then? Note that the change that allowed those and introduced those readonly modifiers in some cases were only merged into 5.1 so removing it really shouldn't affect many people.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I missed that the same PR originally made them readonly. Probably fine then

function checkArrayLiteral(node: ArrayLiteralExpression, checkMode: CheckMode | undefined, forceTuple: boolean | undefined): Type {
const elements = node.elements;
const elementCount = elements.length;
const elementTypes: Type[] = [];
const elementFlags: ElementFlags[] = [];
pushCachedContextualType(node);
const inDestructuringPattern = isAssignmentTarget(node);
const isSpreadIntoCallOrNew = isSpreadElement(node.parent) && isCallOrNewExpression(node.parent.parent);
const inConstContext = isSpreadIntoCallOrNew || isConstContext(node);
Copy link
Member

Choose a reason for hiding this comment

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

The changed baselines that didn’t strictly need to change make this hard to approve. I’d rather not find out that the readonly was important in an untested edge case because of a regression.

@sandersn sandersn added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jun 29, 2023
@sandersn sandersn merged commit 18e1949 into microsoft:main Jun 29, 2023
@Andarist Andarist deleted the fix/parenthesized-spreads-in-calls branch June 29, 2023 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants