Skip to content
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

Return an error if there are two enums with the same name #3669

Merged
merged 2 commits into from Oct 26, 2023

Conversation

thomasetter
Copy link
Contributor

This fixes the issue that two enums with the same name cause the "second" one to overwrite the "first" one.

Currently, looking at the output of target/wasm32-unknown-unknown/wbg-tmp-wasm-<some-hex-characters>.wasm/wasm-bindgen-test.js generated with

WASM_BINDGEN_SPLIT_LINKED_MODULES=1 cargo test --target wasm32-unknown-unknown

the part with the enums (was at line 4849 for me) looks like this:

**
*/
module.exports.Color = Object.freeze({ Green:0,"0":"Green",Yellow:1,"1":"Yellow",Red:2,"2":"Red", });
/**
*/
module.exports.JsRenamedEnum = Object.freeze({ A:10,"10":"A",B:20,"20":"B", });
/**
*/
module.exports.EnumArrayElement = Object.freeze({ Unit:0,"0":"Unit", });
/**
* annotated enum type
*/
module.exports.AnnotatedEnum = Object.freeze({
/**
* annotated enum variant 1
*/
Variant1:0,"0":"Variant1",
/**
* annotated enum variant 2
*/
Variant2:1,"1":"Variant2", });
/**
*/
module.exports.Color = Object.freeze({ Green:0,"0":"Green",Yellow:1,"1":"Yellow",Red:2,"2":"Red", });
/**
*/
module.exports.ColorWithCustomValues = Object.freeze({ Green:21,"21":"Green",Yellow:34,"34":"Yellow",Red:2,"2":"Red", });
/**
*/
module.exports.MyEnum = Object.freeze({ One:1,"1":"One",Two:2,"2":"Two", });

The second assignment module.exports.Color = overwrites the first one, causing the first one to have no effect.

The reason this was not captured by the tests is that the two enums were identical in shape (same unit keys/values).

Copy link
Collaborator

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

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

LGTM!
Could you add a note in the changelog as well?

@thomasetter
Copy link
Contributor Author

Thanks for the quick review, added a note in the changelog under Changed.

CHANGELOG.md Outdated Show resolved Hide resolved
@daxpedda daxpedda merged commit 54f22ee into rustwasm:main Oct 26, 2023
23 checks passed
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.

None yet

2 participants