Skip to content

keep order of provided object constructor fields in sem - #1058

Open
metagn wants to merge 3 commits into
nim-lang:masterfrom
metagn:reordered-obj-constr
Open

keep order of provided object constructor fields in sem#1058
metagn wants to merge 3 commits into
nim-lang:masterfrom
metagn:reordered-obj-constr

Conversation

@metagn

@metagn metagn commented May 2, 2025

Copy link
Copy Markdown
Collaborator

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

metagn commented May 2, 2025

Copy link
Copy Markdown
Collaborator Author

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

@Araq

Araq commented May 2, 2025

Copy link
Copy Markdown
Member

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