Fix l1-config-types-object language test#2190
Open
iwahbe wants to merge 9 commits into
Open
Conversation
Resolve the `l1-config-types-object` conformance failure by lowering
inline `object(...)`, `map(...)`, and dynamic configuration types to
`Map<String, Object>` (or `Map<String, ELEMENT>` for typed maps) via
the new `requireObject(key, TypeShape)` SDK overloads, and by rewiring
the traversal/expression pipeline so that attribute and index access
on those values uses Java collection semantics.
- `genConfigVariable` chooses `requireObject`/`getObject` with a
generated `TypeShape` for map, object, and dynamic config kinds.
- Add `requireObject(key, TypeShape)` and
`requireSecretObject(key, TypeShape)` to `com.pulumi.Config`.
- `genRelativeTraversal` now buffers the chain and switches attribute
steps to `.get("key")` when the root is a `*pcl.ConfigVariable` of
map/object/dynamic kind; list indexing on a value whose Java static
type has been erased to `Object` is wrapped in a `(java.util.List)`
cast.
- `GenIndexExpression` lowers `aMap[k]` to `aMap.get(k)` for
`*model.MapType`/dynamic collections.
- `genIntrinsic` emits explicit numeric/boolean/string casts when
converting from a dynamically-typed value to a concrete type, so
arithmetic like `anyObject.a + anyObject.b` compiles.
- Regenerate two program-codegen golden files that relied on
`[idx]` indexing of Java `List` values, which never actually
compiled in Java.
Fixes #2005
For each `config "<name>" "object({...})" {}` declaration the Java
codegen now emits a nested static class `<Name>Config` containing a
Gson-deserializable public field and a method accessor per property.
The config retrieval call uses `requireObject(key, <Name>Config.class)`
and traversals use the existing `.attr()` getter style — no
`Map<String, Object>` lowering, no runtime casts.
Drop the `objectAsMap` flag and the `(java.util.List)` cast injection
that worked around the previous Map-based lowering; `*model.ObjectType`
now uniformly uses method accessors, matching how the synthetic `range`
iteration variable and schema-typed resource outputs already worked.
Dynamic / untyped (`config "x" {}`) values still come back as
`Map<String, Object>` since their shape isn't known at codegen time.
0f8d7dd to
e59bd2c
Compare
- Drop `staticTypeErased` bookkeeping and `mapValueErasesToObject`. These guarded a `(java.util.List)` cast injection for traversals that crossed a `Map<String, Object>` boundary. With typed POJOs for `object(...)` configs the only remaining `Map<String, Object>` source is a `dynamic` config, and PCL traversal on dynamic stays dynamic rather than becoming a list — so the cast branch was unreachable. - `genRelativeTraversal` now writes directly to the output writer instead of buffering a `chain` string. - `genConfigVariable` defaults `typeSuffix` to `"Object"` and overrides it only for the primitive cases, removing duplicate assignments. - `isMapLikeType`/`isListLikeType` no longer unwrap optionals; callers do it once at the top, so we don't traverse the union twice.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Implements
l1-config-types-objectby teaching the Java program codegen to handle map, object, and dynamic configuration types.object(...)configs: synthesize a nested static class<Name>ConfiginsideAppwith a private field and method accessor per property. The retrieval call becomesconfig.requireObject(\"<key>\", <Name>Config.class), which Gson deserializes via reflection.map(...)configs: lower toconfig.requireObject(key, TypeShape.map(String.class, <Element>.class)), with attribute and index access generating.get(key)for the resultingjava.util.Map.config \"x\" {}): retrieved asMap<String, Object>via the dynamicTypeShape. The intrinsic-convert lowering emits a((Number) ...).doubleValue()/((Boolean) ...)/((String) ...)cast so arithmetic and equality on dynamic values compiles. The traversal tracks when it has crossed a dynamic boundary and inserts a(java.util.List)cast before any subsequent list indexing.Config.requireObject(key, TypeShape)andConfig.requireSecretObject(key, TypeShape), mirroring the existingClass<T>overloads.Fixes #2005.
Test plan