Skip to content

fix error with function evaluating arguments in the wrong order#5276

Draft
giacomocavalieri wants to merge 1 commit intogleam-lang:mainfrom
giacomocavalieri:fix-5272
Draft

fix error with function evaluating arguments in the wrong order#5276
giacomocavalieri wants to merge 1 commit intogleam-lang:mainfrom
giacomocavalieri:fix-5272

Conversation

@giacomocavalieri
Copy link
Member

This PR closes #5272
I'm not so sure about the JS solution, what do you think?


  • The changes in this PR have been discussed beforehand in an issue
  • The issue for this PR has been linked
  • Tests have been added for new behaviour
  • The changelog has been updated for any user-facing changes

@giacomocavalieri giacomocavalieri force-pushed the fix-5272 branch 2 times, most recently from f402e61 to f0e78c8 Compare January 15, 2026 18:36
Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Thank you! Couple notes inline 🙏

Looking at this now, would it not make sense to expand calls with labels to a series of statements prior to codegen? This would mean not needing to duplicate the code across both target code generators, and we wouldn't need to add another special case to collapse blocks in codegen.

Arg = 'fun'(<<"evaluated first"/utf8>>),
Arg@1 = 'fun'(<<"evaluated second"/utf8>>),
wibble(Arg@1, Arg)
end.
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove these redundant blocks? 🙏

export function main() {
(() => { let arg = fun("evaluated first");
let arg$1 = fun("evaluated second");
return wibble(arg$1, arg); })();
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove these redundant IIFEs? They have a performance cost.

For any that we are to keep, can we fix the formatting please 🙏

@giacomocavalieri
Copy link
Member Author

Oh I haven't thought of it that's a great idea! I'll change the implementation

@lpil
Copy link
Member

lpil commented Jan 16, 2026

Sweet, thank you!

@giacomocavalieri giacomocavalieri marked this pull request as draft January 16, 2026 11:53
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.

Changing order of labels in a function call does not change order of evaluation.

2 participants