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

fix(go,python/java): bad code for members with same name with different casing #2699

Merged
merged 22 commits into from
Mar 16, 2021

Conversation

eladb
Copy link
Contributor

@eladb eladb commented Mar 15, 2021

In TypeScript, it is possible to give two members (methods/properties) the same name but with different capitalization. This results in duplicate members in Go and Python.

In Go, where the member is expected to be PascalCase, use the same conversion used in .NET, in which we only capitalize the first letter (assuming TypeScript uses camelCase). This offers more tolerance.

In Python, where members use snake_case, we implemented a different heuristic in which we only render the non-deprecated member and fail if there is more than one deprecated member.

In Java, this issue existed only for property names.

Fixes #2508

BREAKING CHANGE: if multiple members have the same name with different capitalization, only one is allowed to be non-deprecated. This will currently only manifest when producing python bindings, but will be added as a jsii compiler error in the future.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Elad Ben-Israel added 13 commits March 14, 2021 12:34
Go pacmak will reimplement methods and properties in case the class has more than a single "base" (interface/class). The Go code generator failed to include these members when determining which imports to generate.

Add a calc test fixture to verify (failed without this change).

Fixes #2647
When a foreign type is referenced within a complex type (array/list), it wasn't included in the import rendering.

Fixes #2689
…same base name

If a struct has two parent structs with the same base name (but different packages), the emitted conversion function will have the same name (`ToParentStruct` and `ToParentStruct`).

Since we are not even sure that these base conversion functions are required, omit them for now and we can decide to restore them at a later stage if the use case is clearer.

Fixes #2692
It is common in TypeScript to use `_` as an argument name if the argument is not used. This is an invalid name in Go, so replace it with `_arg`.

Fixes #2530
…pitalization

In TypeScript, it is possible to give two members (methods/properties) the same name but with different capitalization. This results in duplicate members in Go and Python.

In Go, where the member is expected to be PascalCase, use the same conversion used in .NET, in which we only capitalize the first letter (assuming TypeScript uses camelCase). This offers more tolerance.

In Python, where members use snake_case, we implemented a different heuristic in which we only render the non-deprecated member and fail if there is more than one deprecated member.

Fixes #2508
@eladb eladb requested review from RomainMuller and MrArnoldPalmer and removed request for RomainMuller March 15, 2021 07:44
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Mar 15, 2021
@eladb eladb requested a review from iliapolo March 15, 2021 07:44
@eladb eladb added the pr/do-not-merge This PR should not be merged at this time. label Mar 15, 2021
Base automatically changed from benisrae/replace_underscore to benisrae/fix-duplicate-conversions March 15, 2021 12:52
Base automatically changed from benisrae/fix-duplicate-conversions to main March 15, 2021 15:08
…ce (#2701)

If a class implements an interface from multiple paths (e.g. directly and via a base), then Go compilation fails with an ambiguity issue.

Simplify by always re-implementing all methods and properties in derived classes.

Fixes #2700
@eladb eladb removed the pr/do-not-merge This PR should not be merged at this time. label Mar 15, 2021
@eladb eladb changed the title fix(go,python): bad code for members with same name with different casing fix(go,python/java): bad code for members with same name with different casing Mar 16, 2021
@eladb eladb merged commit 25528fb into main Mar 16, 2021
@eladb eladb deleted the benisrae/fix-go-duplicate-names branch March 16, 2021 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

go/python: members with same name but different capitalization result in duplicate declarations
3 participants