[program-gen] Fix enum resolution from types of the form Union[string, Enum] and emit fully qualified enum cases #15696
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR improves enum type resolution from strings. When we try to resolve
Union[string, Enum]
for a string expression, we choosestring
because it is the more general type since not every string is assignable toEnum
. However, here we spacial case strings that are actually part of thatEnum
.The result is that
pcl.LowerConversion
will chooseEnum
fromUnion[string, Enum]
when the value of the input string is compatible with the enum. This greatly improves program-gen for all of typescript, python, csharp and go which now will emit the fully qualified enum cases instead of emitting strings.Closes pulumi/pulumi-dotnet#41 which is supposed to be a duplicate of pulumi/pulumi-azure-native#2616 but that is not the case (the former is about unions of objects, the latter is unions of enums and strings)
Checklist
make tidy
to update any new dependenciesmake lint
to verify my code passes the lint checkgofumpt
make changelog
and committed thechangelog/pending/<file>
documenting my change