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

go/python: members with same name but different capitalization result in duplicate declarations #2508

Closed
2 tasks done
Tracked by #13399
eladb opened this issue Feb 2, 2021 · 3 comments · Fixed by #2699
Closed
2 tasks done
Tracked by #13399
Assignees
Labels
bug This issue is a bug. cdk-blocker effort/small Small work item – less than a day of effort p2

Comments

@eladb
Copy link
Contributor

eladb commented Feb 2, 2021

🐛 Bug Report

Affected Languages

  • Python (second method overrides first)
  • Golang

General Information

  • JSII Version: 1.18.0
  • Platform: all

What is the problem?

If a class has two methods with the same name but slightly different capitalization, the go code generator may end up with the same method name and eventually result in a duplicate definition error.

For example, in CDK8s, we had the following:

  public toIsoString(): string { ... }

  /** @deprecated */
  public toISOString(): string { ... }

This resulted in the following error during jsii-pacmak:

# github.com/awslabs/cdk8s-go/cdk8s/cdk8s
./cdk8s.go:1074:2: duplicate method ToIsoString
./cdk8s.go:1237:20: (*Duration).ToIsoString redeclared in this block
 	previous declaration at ./cdk8s.go:1224:6
@eladb eladb added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 2, 2021
@eladb eladb added this to the Go Sprint Jan 20 - Feb 2 2021 milestone Feb 2, 2021
@MrArnoldPalmer MrArnoldPalmer added effort/small Small work item – less than a day of effort p2 and removed needs-triage This issue or PR still needs to be triaged. labels Feb 16, 2021
@eladb
Copy link
Contributor Author

eladb commented Mar 4, 2021

This is technically blocking the release of CDK for Go since the Duration class has two methods with the same name toIsoString() and toISOString(), but I think it might be okay to break this API since this method has been deprecated for ages.

@eladb eladb assigned eladb and unassigned MrArnoldPalmer Mar 14, 2021
@eladb eladb changed the title go: two methods with the similar but different capitalization result in duplicate declarations go/python: two methods with the similar but different capitalization result in duplicate declarations Mar 14, 2021
@eladb eladb changed the title go/python: two methods with the similar but different capitalization result in duplicate declarations go/python: two methods with different capitalization result in duplicate declarations Mar 14, 2021
@eladb eladb changed the title go/python: two methods with different capitalization result in duplicate declarations go/python: members with same name but different capitalization result in duplicate declarations Mar 14, 2021
@eladb
Copy link
Contributor Author

eladb commented Mar 14, 2021

This also happens in Python albeit does not produce an error during build and the methods just override each other.

The Duration.to_iso_string() method is indicated to be "deprecated", but there is actually a non-deprecated toIsoString() method which is not accessible.

eladb pushed a commit that referenced this issue Mar 15, 2021
…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 pushed a commit that referenced this issue Mar 16, 2021
…nt casing (#2699)

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.
@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

mergify bot pushed a commit to aws/aws-cdk that referenced this issue Mar 25, 2021
Add `go` configuration to the `monocdk` and `aws-cdk-lib` packages. 

Resolves aws/jsii#2611

The following jsii bugs were fixed to enable this:

- [x] aws/jsii#2648
- [x] aws/jsii#2649
- [x] aws/jsii#2647
- [x] aws/jsii#2617
- [x] aws/jsii#2632
- [x] aws/jsii#2651
- [x] aws/jsii#2508
- [x] aws/jsii#2692
- [x] aws/jsii#2700
- [x] aws/jsii#2702

---

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
corrjo pushed a commit to corrjo/aws-cdk that referenced this issue Mar 25, 2021
Add `go` configuration to the `monocdk` and `aws-cdk-lib` packages.

Resolves aws/jsii#2611

The following jsii bugs were fixed to enable this:

- [x] aws/jsii#2648
- [x] aws/jsii#2649
- [x] aws/jsii#2647
- [x] aws/jsii#2617
- [x] aws/jsii#2632
- [x] aws/jsii#2651
- [x] aws/jsii#2508
- [x] aws/jsii#2692
- [x] aws/jsii#2700
- [x] aws/jsii#2702

---

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this issue Mar 31, 2021
Add `go` configuration to the `monocdk` and `aws-cdk-lib` packages. 

Resolves aws/jsii#2611

The following jsii bugs were fixed to enable this:

- [x] aws/jsii#2648
- [x] aws/jsii#2649
- [x] aws/jsii#2647
- [x] aws/jsii#2617
- [x] aws/jsii#2632
- [x] aws/jsii#2651
- [x] aws/jsii#2508
- [x] aws/jsii#2692
- [x] aws/jsii#2700
- [x] aws/jsii#2702

---

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this issue Aug 26, 2021
Add `go` configuration to the `monocdk` and `aws-cdk-lib` packages.

Resolves aws/jsii#2611

The following jsii bugs were fixed to enable this:

- [x] aws/jsii#2648
- [x] aws/jsii#2649
- [x] aws/jsii#2647
- [x] aws/jsii#2617
- [x] aws/jsii#2632
- [x] aws/jsii#2651
- [x] aws/jsii#2508
- [x] aws/jsii#2692
- [x] aws/jsii#2700
- [x] aws/jsii#2702

---

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
eladb pushed a commit to cdklabs/decdk that referenced this issue Jan 18, 2022
Add `go` configuration to the `monocdk` and `aws-cdk-lib` packages. 

Resolves aws/jsii#2611

The following jsii bugs were fixed to enable this:

- [x] aws/jsii#2648
- [x] aws/jsii#2649
- [x] aws/jsii#2647
- [x] aws/jsii#2617
- [x] aws/jsii#2632
- [x] aws/jsii#2651
- [x] aws/jsii#2508
- [x] aws/jsii#2692
- [x] aws/jsii#2700
- [x] aws/jsii#2702

---

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. cdk-blocker effort/small Small work item – less than a day of effort p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants