Skip to content

main: don't mutate compile options in Test - #5468

Merged
deadprogram merged 1 commit into
tinygo-org:devfrom
jakebailey:test-options-copy
Jun 19, 2026
Merged

main: don't mutate compile options in Test#5468
deadprogram merged 1 commit into
tinygo-org:devfrom
jakebailey:test-options-copy

Conversation

@jakebailey

Copy link
Copy Markdown
Member

This function modifies TestConfig, but Test is called from multiple places, so can cause a data race. (and in the presence of races, all behavior bets are off).

Comment thread main.go
Comment on lines +212 to +213
optionsCopy := *options
options = &optionsCopy

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This fix works, but leaves the footgun. If it weren't for its size, compileopts.Options should be passed by value.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It probably wouldn't be a big deal to just make it a value arg; either way it's going to get copied...

@deadprogram

Copy link
Copy Markdown
Member

Since it does improve the current code it is a step in the correct direction. We can discuss changing the interface to pass by value in a future PR.

Now merging, thanks for the fix @jakebailey and to @eliasnaur for review.

@deadprogram
deadprogram merged commit 6a0acfc into tinygo-org:dev Jun 19, 2026
25 of 26 checks passed
@jakebailey
jakebailey deleted the test-options-copy branch July 3, 2026 21:31
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.

3 participants