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(pacmak): illegal static overrides in java & c# #2373

Merged
merged 5 commits into from
Dec 22, 2020

Conversation

RomainMuller
Copy link
Contributor

Stop emitting "overrides" in the respecting language idiomatic way for
static methods and properties (while ES6 supports those, this is not
true of Java and C#).

In Java, this is mostly getting rid of @Overrides on static
declarations. C# allows (but does not require) explicitly hiding the
parent declaration using the new keyword. This was introduced as it
provides additional safeguards against our generating incorrect code.

Fixes #2358


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

@RomainMuller RomainMuller added effort/small Small work item – less than a day of effort module/pacmak Issues affecting the `jsii-pacmak` module labels Dec 21, 2020
@RomainMuller RomainMuller requested a review from a team December 21, 2020 16:02
@RomainMuller RomainMuller self-assigned this Dec 21, 2020
Stop emitting "overrides" in the respecting language idiomatic way for
static methods and properties (while ES6 supports those, this is not
true of Java and C#).

In Java, this is mostly getting rid of `@Overrides` on static
declarations. C# *allows* (but does not require) explicitly hiding the
parent declaration using the `new` keyword. This was introduced as it
provides additional safeguards against our generating incorrect code.

Fixes #2358
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Dec 21, 2020
Copy link
Contributor

@NetaNir NetaNir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, mostly "take it or leave it" comments, approved and added do not merge (we really need an emoji for this type of comments).

I initially thought we should implements this fix by emitting the override annotation for the assembly file, but Im guessing it will be less ideal since we will be losing important information?
Maybe we can formalize this behavior in the jsii spec level? Adding a static-overrides section in the assembly?

} else if (
!method.static &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this logic be moved to the if (method.overrides) clause above? Reasoning being that we treat static overrides as not overrides, and this can reduce the nesting in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been internally debating this a little bit... Initially I wanted to simply change the compiler so that statics are never considered to be overrides; but this caused problems, because in JavaScript (and hence, TypeScript), they actually are overrides... This manifests when you try the following:

export class Parent { public static foo: number; }

//! Child.foo incorrectly implements Parent.foo (types don't match)
export class Child extends Parent { public static foo: string; }

This made me decide that it was a more coherent story from the author's standpoint if we reproduced the ES6 semantics in the jsii assembly (where statics are inherited with the rest of the prototype). Carrying them as overrides has advantages - in languages where static are inherited (although JS is the only one that comes to mind now), this allows overrides to use super.

We could distinguish static overrides from non-static overrides, however this distinction is very much a code generation concern, and not so much a type model concern (after all, all we care about is whether this is an override or not, period).

packages/jsii-calc/lib/compliance.ts Outdated Show resolved Hide resolved
packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts Outdated Show resolved Hide resolved
@NetaNir NetaNir added the pr/do-not-merge This PR should not be merged at this time. label Dec 21, 2020
@RomainMuller RomainMuller added this to the 🎄 December Release milestone Dec 22, 2020
@RomainMuller RomainMuller removed the pr/do-not-merge This PR should not be merged at this time. label Dec 22, 2020
@mergify
Copy link
Contributor

mergify bot commented Dec 22, 2020

Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it!

@mergify mergify bot added the pr/ready-to-merge This PR is ready to be merged. label Dec 22, 2020
@mergify
Copy link
Contributor

mergify bot commented Dec 22, 2020

Merging (with squash)...

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-5lHf64IXfvmr
  • Commit ID: 4aaac98
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 4672e4b into main Dec 22, 2020
@mergify mergify bot deleted the rmuller/static-homonyms branch December 22, 2020 13:51
@mergify
Copy link
Contributor

mergify bot commented Dec 22, 2020

Merging (with squash)...

@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label Dec 22, 2020
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. effort/small Small work item – less than a day of effort module/pacmak Issues affecting the `jsii-pacmak` module
Projects
None yet
3 participants