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 #7

Closed
wants to merge 2 commits into from

Conversation

thomasetter
Copy link
Owner

@thomasetter thomasetter commented Oct 24, 2023

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).

@thomasetter thomasetter force-pushed the enum-collision-fix branch 2 times, most recently from a93da60 to 3f5fd0a Compare October 25, 2023 14:39
@thomasetter thomasetter changed the title Fix the issue that one could define two enums with the second one overwriting the first one. Fix the issue that two enums with the same name with the "second" one overwriting the "first" one. Oct 25, 2023
@thomasetter thomasetter changed the title Fix the issue that two enums with the same name with the "second" one overwriting the "first" one. Return an error if there are two enums with the same name Oct 25, 2023
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.

2 participants