Skip to content

Fix destructuring assignment errors#1529

Merged
gbrail merged 2 commits intomozilla:masterfrom
tuchida:fix-destructuring-assignment-errors
Jul 22, 2024
Merged

Fix destructuring assignment errors#1529
gbrail merged 2 commits intomozilla:masterfrom
tuchida:fix-destructuring-assignment-errors

Conversation

@tuchida
Copy link
Contributor

@tuchida tuchida commented Jul 18, 2024

Closes #1187

js> var a = []; var b = 0; [a[b+1]] = [123];
Exception in thread "main" java.lang.NullPointerException
	at org.mozilla.javascript.optimizer.BodyCodegen.generateExpression(BodyCodegen.java:967)
	at org.mozilla.javascript.optimizer.BodyCodegen.generateExpression(BodyCodegen.java:1233)
	at org.mozilla.javascript.optimizer.BodyCodegen.visitSetElem(BodyCodegen.java:4143)

This error has been corrected in this commit.

Closes #406

js> (1 ? {} : 490) = 1
Exception in thread "main" java.lang.ClassCastException: class org.mozilla.javascript.Node cannot be cast to class org.mozilla.javascript.ast.ObjectLiteral (org.mozilla.javascript.Node and org.mozilla.javascript.ast.ObjectLiteral are in unnamed module of loader 'app')
	at org.mozilla.javascript.Parser.destructuringAssignmentHelper(Parser.java:4046)
	at org.mozilla.javascript.Parser.createDestructuringAssignment(Parser.java:4016)
	at org.mozilla.javascript.IRFactory.createAssignment(IRFactory.java:2056)

This error has been corrected in this commit.

@p-bakker
Copy link
Collaborator

Nice!

Copy link
Contributor Author

@tuchida tuchida left a comment

Choose a reason for hiding this comment

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

Node d = parser.createDestructuringAssignment(node.getType(), left, right);

Because a variable declaration cannot be an expression, no transform is passed here.

var [a.b] = []; // SyntaxError

Node newBody = new Node(Token.BLOCK);
Node assign;
if (destructuring != -1) {
assign = parser.createDestructuringAssignment(declType, lvalue, id);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

var a;
for ([a] of [[1], [2], [3]]) {
  //
}

return right;
}
return parser.createDestructuringAssignment(-1, left, right);
return parser.createDestructuringAssignment(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

var a;
[a] = [1];

@tuchida tuchida marked this pull request as ready for review July 18, 2024 17:08
scope-paramsbody-var-close.js
scope-paramsbody-var-open.js

language/expressions/assignment 200/468 (42.74%)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm trying to refresh my memory on test262.properties -- is this a long list of tests that we now have to disable becuase we broke them, or were these tests never run and we're actually able to pass 58% of them?

In other words, do these test262 changes represent an improvement, or a regression?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The test262Suite only looks at tests in directories that are already included in trst262.properties

So what you're seeing here in inclusion of a new directory full of tests, some of which already pass

Ran into this recently, tried to create a PR that will include ALL directories automatically, because this is a gap in our 'security net'. Didn't get around to finish it though....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

f772166 First I added language/expressions/assignment tests to test262.properties in the first commit.
1fd026f And two of those tests were improved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added all directories to test262.properties. ref. #1531
I would like to merge that PR first.

@gbrail
Copy link
Collaborator

gbrail commented Jul 21, 2024

This looks good, but I merged your other 262.properties change and I'd feel better if you looked it over and resolved before merging. Thanks!

@tuchida
Copy link
Contributor Author

tuchida commented Jul 21, 2024

f772166 Add assignment tests of test262

I deleted the commit. No other changes have been made.

@gbrail
Copy link
Collaborator

gbrail commented Jul 22, 2024

Thanks for working on this!

@gbrail gbrail merged commit 7525f81 into mozilla:master Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error with destructuring array assignment(?) ClassCastException when compiling malformed destructuring expression

3 participants