-
Notifications
You must be signed in to change notification settings - Fork 197
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
convert to valid identifier before checking for collision #942
base: main
Are you sure you want to change the base?
Conversation
Convert to snake case *before* checking for keyword collisions, so C and C++ keywords with underscores will be “escaped” as well.
could you add a test case in https://github.com/bytecodealliance/wit-bindgen/tree/main/tests/codegen? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@primoly looks like a few tests are failing with this change |
It seems like the Go bindgen was broken for this change |
The name generation for Go is quite a bit more involved due to the conversions and collision checks being done in different functions and files and handled differently on a case-by-case basis (keyword escapes/name mangling, snake/camel, Go/C). Because #784 (comment) might supersede the bindgen here (?) I’m unsure if fixing this now would be worth the effort. Also, the current camel case conversion, for example, turns Maybe it makes sense to just drop that test since it is very unlikely that all caps keywords will appear in Wit names since they are usually not acronyms. On the other hand I believe automated binding generators should generally be able to handle edge cases since these kinds of issues, while rare, are really difficult to debug when they do occur. |
I generally agree but lets get some input from @alexcrichton |
I definitely think this is a good test to add, thanks! Feel free to add ignores for other generators and maintainers can get around to supporting them after this PR lands. |
Yeah feel free to ignore the tests for Go at the moment. I will take a step to fix them as soon as I got some time. (might be a good idea to create an issue to track since I sometimes forgot things)
I am hoping to do some refactoring work to make this centralized and easier to change.
I intend to still maintain this project to pass all the test cases since it's been used in several other projects, while waiting for the new wit-bindgen-go to land. |
Because the current
to_*_ident
functions check for collisions with keywords before converting to snake/camel case some edge cases are missed. For example with the following type in Wit:wit-bindgen currently generates fields, attributes and parameters named
const
andbreak
.This commit also resolves the
//TODO: Repace with actual keywords
in the C# bindings generator.