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

[program-gen] Fix enum resolution from types of the form Union[string, Enum] and emit fully qualified enum cases #15696

Merged
merged 1 commit into from Mar 15, 2024

Conversation

Zaid-Ajaj
Copy link
Contributor

Description

This PR improves enum type resolution from strings. When we try to resolve Union[string, Enum] for a string expression, we choose string because it is the more general type since not every string is assignable to Enum. However, here we spacial case strings that are actually part of that Enum.

The result is that pcl.LowerConversion will choose Enum from Union[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

  • I have run make tidy to update any new dependencies
  • I have run make lint to verify my code passes the lint check
    • I have formatted my code using gofumpt
  • I have added tests that prove my fix is effective or that my feature works
  • I have run make changelog and committed the changelog/pending/<file> documenting my change
  • Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version

@Zaid-Ajaj Zaid-Ajaj added the area/codegen SDK-gen, program-gen, convert label Mar 15, 2024
@Zaid-Ajaj Zaid-Ajaj requested a review from a team as a code owner March 15, 2024 01:08
@pulumi-bot
Copy link
Contributor

Changelog

[uncommitted] (2024-03-15)

Bug Fixes

  • [programgen/{dotnet,go,nodejs,python}] Fix enum resolution from types of the form union[string, enum]
    #15696

@Zaid-Ajaj Zaid-Ajaj force-pushed the zaid/fix-list-of-enum-union-in-csharp branch from 3457547 to cf56a89 Compare March 15, 2024 16:58
@Zaid-Ajaj Zaid-Ajaj added this pull request to the merge queue Mar 15, 2024
Merged via the queue into master with commit 3bdc65c Mar 15, 2024
58 of 59 checks passed
@Zaid-Ajaj Zaid-Ajaj deleted the zaid/fix-list-of-enum-union-in-csharp branch March 15, 2024 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/codegen SDK-gen, program-gen, convert
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[dotnet/programgen] programgen produces incorrect code for union[object, object] types
3 participants