Skip to content

keep order of provided object constructor fields in sem #1058

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

metagn
Copy link
Collaborator

@metagn metagn commented May 2, 2025

closes #1056 (for the sem issue, evaluation order is still not fixed)

The compiler reorders the fields of an object constructor depending on the field order of the object type, this PR makes it so that provided fields are kept in the order that they were provided and only the default fields keep the object type order. This still encounters UB in the generated C so it doesn't fix the evaluation order, but it might still be useful, and things like:

Foo(
  b: (let x = 123; x),
  a: x)

won't break on resem.

@metagn metagn changed the title test not reordering already given object constructor fields keep order of provided object constructor fields in sem May 2, 2025
@metagn metagn marked this pull request as ready for review May 2, 2025 19:56
@metagn
Copy link
Collaborator Author

metagn commented May 2, 2025

Ended up not fully fixing the issue, could close and postpone this for compat mode.

@Araq
Copy link
Member

Araq commented May 2, 2025

I think sem should produce a warning or an error if there are function calls involved and the order of the fields differs from the declaration order. I don't see the benefit in allowing an arbitrary order in 2025 when auto-completion is now so good it threatens our jobs anyway.

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.

object constructor generation field reordering in sem breaks order of evaluation
2 participants