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): .NET bindings fail to compile with error CS8120 #3760

Merged
merged 6 commits into from
Sep 22, 2022

Conversation

RomainMuller
Copy link
Contributor

If a type union includes several candidates that are related to each other (A extends B or A implements B), jsii-pacmak may generate type checking clauses in a pattern matching switch statement in an order such that the compiler identifies dead clauses, which is an error in C#.

This adds a provision to NOT emit such a clause so as to not cause the error. It is worth mentioning that the error cannot be "opted out" of via a #pragma directive like a warning would be, which is unfortunate.

Fixes #3759


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

If a type union includes several candidates that are related to each
other (A extends B or A implements B), `jsii-pacmak` may generate type
checking clauses in a pattern matching `switch` statement in an order
such that the compiler identifies dead clauses, which is an error in C#.

This adds a provision to NOT emit such a clause so as to not cause the
error. It is worth mentioning that the error cannot be "opted out" of
via a `#pragma` directive like a warning would be, which is unfortunate.

Fixes #3759
@RomainMuller RomainMuller requested a review from a team September 21, 2022 13:47
@RomainMuller RomainMuller self-assigned this Sep 21, 2022
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Sep 21, 2022
@@ -21,5 +21,6 @@
"composite": true, /* Ensure TypeScript can determine where to find the outputs of the referenced project to compile project. */
"incremental": true, /* Enable incremental compilation by reading/writing information from prior compilations to a file on disk. */
"useDefineForClassFields": false, /* Use Object.defineProperty for introducing class fields. */
"skipLibCheck": true, /* Skip type checking of declaration files. */
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems unrelated, was this an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this is unrelated but does not hurt :) It's a recommended setting in TypeScript and could make builds somewhat faster.

@@ -172,6 +172,26 @@ abstract class Validation {
code.openBlock(`switch (${expression})`);
for (const type of types) {
validTypes.push(resolver.toDotNetTypeName(type.spec!));

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Great explanation 👍

@mergify
Copy link
Contributor

mergify bot commented Sep 21, 2022

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 Sep 21, 2022
@mergify
Copy link
Contributor

mergify bot commented Sep 21, 2022

Merging (with squash)...

1 similar comment
@mergify
Copy link
Contributor

mergify bot commented Sep 21, 2022

Merging (with squash)...

@mergify
Copy link
Contributor

mergify bot commented Sep 22, 2022

Merging (with squash)...

@RomainMuller
Copy link
Contributor Author

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Sep 22, 2022

update

✅ Branch has been successfully updated

@mergify
Copy link
Contributor

mergify bot commented Sep 22, 2022

Merging (with squash)...

@mergify mergify bot merged commit 783ec7f into main Sep 22, 2022
@mergify mergify bot deleted the rmuller/union-with-implied-type branch September 22, 2022 10:02
@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label Sep 22, 2022
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.

C# Runtime check fails on compilation
3 participants