-
Notifications
You must be signed in to change notification settings - Fork 246
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
Rosetta: Incorrect transliteration for namespace/submodule usage in Go #3551
Comments
That's a tricky one... the issue here is that the original TypeScript traverses a namespace boundary here ( This is actually quite different from #3508 in the sense that we need to modify the list of go packages to import here, but we only "discover" this information after it's too late (we already emitted imports at that stage). In order to address this, we'd need to either:
|
I'm exploring a possible solution. I expect it'll take me probably a few days to get through this (unless I discover I am overthinking it). |
Java and Go do not support transitive access to a submodule's items via a qualified reference and instead require a dedicated import to be emitted. This adds code to analyze use of imported symbols to detect when a namespace traversal occurs, to inject new imports & replace property access expressions as necessary. In order to facilitate this work, these extra elements were done: - Replaced if-tree in the dispatcher with a switch statement, making the dispatch a lot faster, and also a lot nice to run through in a debugger - Emit `var` instead of a type name for variable declarations with an initializer in C#, to reduce "invalid" code generated in cases where the type name needs some qualification that we are missing - A couple of bug fixes here and there as the tests discovered them Fixes #3551
Java and Go do not support transitive access to a submodule's items via a qualified reference and instead require a dedicated import to be emitted. This adds code to analyze use of imported symbols to detect when a namespace traversal occurs, to inject new imports & replace property access expressions as necessary. In order to facilitate this work, these extra elements were done: - Replaced if-tree in the dispatcher with a switch statement, making the dispatch a lot faster, and also a lot nice to run through in a debugger - Emit `var` instead of a type name for variable declarations with an initializer in C#, to reduce "invalid" code generated in cases where the type name needs some qualification that we are missing - A couple of bug fixes here and there as the tests discovered them Fixes #3551
Java and Go do not support transitive access to a submodule's items via a qualified reference and instead require a dedicated import to be emitted. This adds code to analyze use of imported symbols to detect when a namespace traversal occurs, to inject new imports & replace property access expressions as necessary. In order to facilitate this work, these extra elements were done: - Replaced if-tree in the dispatcher with a switch statement, making the dispatch a lot faster, and also a lot nice to run through in a debugger - Emit `var` instead of a type name for variable declarations with an initializer in C#, to reduce "invalid" code generated in cases where the type name needs some qualification that we are missing - A couple of bug fixes here and there as the tests discovered them Fixes #3551 --- > **Note**: > There are still some awkward issues with the rendered code, but those are significantly more difficult to tackle without profoundly refactoring `jsii-rosetta`... The current work is already chunky enough and I didn't want to make it worse. > - Some synthetic type references lack qualification (e.g: struct type names in Go & C#) > - There might still be edge cases where duplicated or unused imports are emitted > - Import paths (in Go) may not be computed correctly (this might not be too hard to address, though) --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
|
Describe the bug
Translating a reference to a namespaced resource results in
#error#
being output in the resulting Go code.Expected Behavior
The namespace should be maintained or separate import statements should be generated.
Current Behavior
The namespace is lost and
#error#
is generated instead.Reproduction Steps
results in
Possible Solution
#3508 tackled a similar issue, so there maybe a similar solution available; however, I haven't checked the code.
Additional Information/Context
This came up while working on hashicorp/terraform-cdk#1782.
There is a snapshot test that illustrates the issue.
SDK version used
1.55.1, also observed in 1.58.0
Environment details (OS name and version, etc.)
docker.mirror.hashicorp.services/hashicorp/jsii-terraform (based on jsii/superchain)
The text was updated successfully, but these errors were encountered: