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(.net): missing dynamic type checking for collection-nested unions #3720

Merged
merged 2 commits into from
Aug 23, 2022

Conversation

RomainMuller
Copy link
Contributor

The .NET runtime type checking was not checking type unions that
are nested within a collection (list or map), although this is
necessary since the is <type> guard does not allow making any
assumption about the contents of the collection.

This adds the missing checks, and replaces the guard clauses
with a switch statement using pattern matching, resulting
in somewhat more elegant code (also with better null safety).


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

@RomainMuller RomainMuller self-assigned this Aug 23, 2022
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Aug 23, 2022
Comment on lines +257 to 258
return `${interpolates}"System.Collections.Generic.IDictionary<string, ${elementTypeName}>"`;
default:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tweaked here, because nameof on the generic type does not produce a string that is human-friendly, unfortunately.

Copy link
Contributor

@comcalvi comcalvi left a comment

Choose a reason for hiding this comment

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

That was pretty fast, well done!

}
}

abstract class Validation {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should I use this approach in the Java code gen as well, or stick to the previous way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can if you want, but you can also migrate in a separate PR.

.digest('hex')
.slice(0, 6)}`;

code.openBlock(`switch (${expression})`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want this to be consistent across languages when possible? Should I port this switch approach to Java as well, or leave it as-is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can't do switch like this in Java... it only works with primitive types, enums, String, and certain boxed primitive classes. So you end up having to stick to if/else here, sorry!

@mergify
Copy link
Contributor

mergify bot commented Aug 23, 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 Aug 23, 2022
@mergify
Copy link
Contributor

mergify bot commented Aug 23, 2022

Merging (with squash)...

@mergify mergify bot merged commit 362326e into main Aug 23, 2022
@mergify mergify bot deleted the rmuller/dotnet-nested-union branch August 23, 2022 22:14
@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label Aug 23, 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.

None yet

2 participants