emscripten-core / emscripten-core/emscripten

enum values within namespaces can overwrite each other when using WebIDL

Open
#13,243 5 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

I guess this is a bit of a corner case. Following situation:

C++ code:
```C
namespace NameSpaceA {
enum EnumA {
SomeValue = 1
};
};
namespace NameSpaceB {
enum EnumB {
SomeValue = 17
};
};
// use typedefs so enums in namespaces can be mapped in WebIDL
typedef NameSpaceA::EnumA NameSpaceA_EnumA;
typedef NameSpaceB::EnumB NameSpaceB_EnumB;
````

Corresponding idl file:
```
enum NameSpaceA_EnumA {
"NameSpaceA_EnumA::SomeValue"
};
enum NameSpaceB_EnumB {
"NameSpaceB_EnumB::SomeValue"
};
```

This code compiles. However the problem is that, in javascript, the enum values are accessed by their unquallified name. Hence there is only a single `Module.SomeValue` defined and one of the two values gets lost.

I'm currently mapping nvidia PhysX with WebIDL and such enums are used as flags all over the place. Passing wrong values here can result in pretty weird and unexpected behavior. My current work-around is to use the internal functions generated by WebIDL Binder instead (e.g. `Module._emscripten_enum_NameSpaceA_EnumA_SomeValue()`).

However I think it would be better to map enum values with their quallified name or at least issue some kind of warning since this can produce bugs which are quite hard to track down.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.