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
[dotnet/program-gen] Fixes list initializer for plain lists in resource properties #13630
Conversation
Changelog[uncommitted] (2023-08-07)Bug Fixes
|
// if is it a plain list, then `new()` should be used because we are creating List<T> | ||
// however if we have InputList<T> or anything else, we use `new[]` because InputList<T> can be implicitly casted | ||
// from an array | ||
listInitializer string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bit grim this goes on the generator state? Can't we work this out, and thread it down more locally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bit grim this goes on the generator state?
Yes
Can't we work this out, and thread it down more locally
Not unless we rewrite ExpressionGenerator
because it not possible to know at the point of generating an expression (i.e. GenTupleConsExpxression
for arrays) what context information about that expression is available 😞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh fine
8f6de1d
to
d66a037
Compare
bors merge |
13630: [dotnet/program-gen] Fixes list initializer for plain lists in resource properties r=Zaid-Ajaj a=Zaid-Ajaj # Description Some resources, especially custom resources like those in `awsx` have properties which are _plain_ lists. This means that the generated dotnet SDK for them uses `List<T>` rather than `InputList<T>`. In case of the former, when initializing the list, we cannot use `new[]` (this works for `InputList<T>` because of an implicit conversion from arrays). Instead we have to use `new()` which initializes an instance of the `List<T>` class. This PR implements a fix such that the code generator knows when the current resource property is plain or not and subsequently emitting `new()` instead of `new[]` Fixes pulumi/pulumi-dotnet#21 ## Checklist - [ ] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [ ] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. --> Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
Build failed: |
bors merge |
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
Description
Some resources, especially custom resources like those in
awsx
have properties which are plain lists. This means that the generated dotnet SDK for them usesList<T>
rather thanInputList<T>
. In case of the former, when initializing the list, we cannot usenew[]
(this works forInputList<T>
because of an implicit conversion from arrays). Instead we have to usenew()
which initializes an instance of theList<T>
class.This PR implements a fix such that the code generator knows when the current resource property is plain or not and subsequently emitting
new()
instead ofnew[]
Fixes pulumi/pulumi-dotnet#21
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