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

(jsii) incorrect deprecation warning when two string enums have the same value #3103

Closed
nija-at opened this issue Oct 28, 2021 · 3 comments · Fixed by #3105
Closed

(jsii) incorrect deprecation warning when two string enums have the same value #3103

nija-at opened this issue Oct 28, 2021 · 3 comments · Fixed by #3105
Assignees
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@nija-at
Copy link
Contributor

nija-at commented Oct 28, 2021

🐛 Bug Report

When two string enums have the same value and one is deprecated, the flag --add-deprecation-warnings incorrectly produces a warning when the non-deprecated enum is used.

Example:

https://github.com/aws/aws-cdk/blob/c4ba858278bffe1a987ea8200c313f17f7f1cbe9/packages/%40aws-cdk/core/lib/custom-resource-provider/custom-resource-provider.ts#L83-L93

@nija-at nija-at added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 28, 2021
@njlynch
Copy link
Contributor

njlynch commented Oct 28, 2021

I'm not convinced this is fixable with the current implementation (or at all).

We are checking at the site of usage if the enum matches any of the deprecated enum values. At this point (for this example), the value of the parameter passed in is just 'nodejs12.x', as a string (IIUC). There's literally no way at the call site to know whether CustomResourceProviderRuntime.NODEJS_12 or CustomResourceProviderRuntime.NODEJS_12_X was used.

I think we can either accept a false positive here (warning people erroneously) or we could detect that there are duplicate enum values and do nothing, leading to false negatives (not warning people). I suppose the latter is better, but it's crap either way.

@nija-at
Copy link
Contributor Author

nija-at commented Oct 28, 2021

Feels like the better option is to not warn in these cases.

@njlynch njlynch self-assigned this Oct 28, 2021
njlynch added a commit that referenced this issue Oct 28, 2021
…alues

The deprecation warnings feature will warn if an enum value is used which is
equal to one to a deprecated enum member. Unfortunately, in the case of an enum
with duplicate values, there is no way to tell whether the deprecated member was
used (or not). The current behavior emits warnings even in cases where the
active/undeprecated member is being used.

This change flips the behavior to mute the notification in the case where the
value used is a known duplicate value. This results in erring on the side of
false negatives (not catching deprecated usage) over false positives (warning in
the case nothing's wrong).

fixes #3103
@mergify mergify bot closed this as completed in #3105 Oct 28, 2021
mergify bot pushed a commit that referenced this issue Oct 28, 2021
…alues (#3105)

The deprecation warnings feature will warn if an enum value is used which is
equal to one to a deprecated enum member. Unfortunately, in the case of an enum
with duplicate values, there is no way to tell whether the deprecated member was
used (or not). The current behavior emits warnings even in cases where the
active/undeprecated member is being used.

This change flips the behavior to mute the notification in the case where the
value used is a known duplicate value. This results in erring on the side of
false negatives (not catching deprecated usage) over false positives (warning in
the case nothing's wrong).

fixes #3103



---

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
@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.

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. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants