Commit Graph

12 Commits

Author SHA1 Message Date
Zaid Ajaj 3bdc65c6e5
[program-gen] Fix enum resolution from types of the form Union[string, Enum] and emit fully qualified enum cases ()
# 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 https://github.com/pulumi/pulumi-dotnet/issues/41 which is
supposed to be a duplicate of
https://github.com/pulumi/pulumi-azure-native/issues/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
- [x] I have run `make lint` to verify my code passes the lint check
  - [x] 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. -->
2024-03-15 17:49:12 +00:00
Zaid Ajaj 6a174fa117 Fixes panic when trying to convert a null literal to a string value 2023-06-09 12:52:10 +02:00
Zaid Ajaj b16a359fab Support range expressions that are of type output 2023-05-02 16:07:58 +02:00
Abhinav Gupta e395deef6b
all: Assert => Assertf
Migrates all remaining usages of
`contract.Assert*` and `contract.Require*` to the f variants,
which require adding meaningful error messages.

There were a couple cases where a `testing.T` or `testing.B`
was already available.
For those, this uses t.FailNow or require.NoError.

Refs 
2023-03-03 14:37:43 -08:00
Ian Wahbe 0027297394 Don't return half-nil fat ptrs from `SyntaxNode()`
Passing a typed `nil` through a interface conversion, such as a
`*hclsyntax.UnaryOpExpr` through a `hclsyntax.Node` interface will
result in a half-nil fat pointer with the value part `nil`. Since most
of programgen assumes that `(model.Expression).SyntaxNode().Range()` is
valid, a `syntax.None` is passed instead of a `nil`.
2022-12-16 13:37:08 +01:00
Ian Wahbe d770162254 Remove traverse errors on dynamic types
Preserve traverser src range

Improve testing diags

Re-enable resource type checking

Warn instead of skipping missing resources

Improve explination for the new test

Get test to generate output

Reenable forceing resource type checking

CL

Fix TestBindProgram

Cleanup PR
2022-11-16 14:41:30 -08:00
Thomas Kappler 0ec2616e26 Enable resolving discriminated unions when the discriminator is a string pointer
This fixes broken examples in our documentation.
2022-09-22 14:50:20 -07:00
Aaron Friel a4b1d6b2a7 ci: gofmt 1.18+ clean 2022-09-21 09:48:39 -07:00
Zaid Ajaj 515cf6191c
Fixes panic when generating go from pulumi yaml ()
* Fixes  panic when generating go from pulumi yaml

Co-authored-by: Aaron Friel <friel@pulumi.com>
Co-authored-by: Zaid Ajaj <zaid@pulumi.com>

* rewrite rewriteConversions to accumulate diagnostics, improve errors

* rewrite diags

* update java dependency

* chore: fix go.mod/go.sum

* fix: traversal of multi-part template string expressions

Co-authored-by: Aaron Friel <mayreply@aaronfriel.com>
Co-authored-by: Aaron Friel <friel@pulumi.com>
Co-authored-by: Zaid Ajaj <zaid@pulumi.com>
2022-07-07 13:15:47 -07:00
Ian Wahbe f116792743
Change pcl.LowerConversion to allow invalid conversions ()
* Change pcl.LowerConversion to allow invalid conversions

* Remove unused import
2022-04-20 09:47:34 +02:00
Ian Wahbe 183fa89163
Add an EnumType to the PCL model ()
* Add an EnumType to the PCL model

Languages implementation:
- [X] C#
- [X] Python
- [X] TypeScript
- [X] Go

* Fix assert

* Take namespace settings into account

* Implement enums for Go

* Update tests and add documentation.

* Add a test + handle output&unsafe

* Get outputs compiling for Go

* Line up types for Go

* Add nodejs

* Add Python

* Change expression form

* Fix nil check (`==` -> `!=`)

* Standardize nodejs & python checks

This should fix the Node OOM error.

* Rename enum-py to typed-enum-pp

* Don't reference schema types in `hcl2/model`

* Fix nits
2022-04-18 11:03:42 +02:00
Pat Gavlin f21eda521f
[codegen] Rename the PCL package. ()
It's just confusing that PCL lives in a package named `hcl2`.
2021-09-29 20:11:56 -07:00