Amending an undefined property with a union type with no default member should produce a more specific error
- Dominant language
- Java
- Stars
- 11.5k
- Forks
- 402
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 20
Description
When a field is typed as `Listing` or `String`, Pkl will fail to intuit the type of the value if it inherits from Dynamic. `Int` will also be intuited correctly, whereas `Mapping` is also not intuited.
**Example:**
```pkl
class ExampleTyped {
aa: Listing | String
bb: String
}
typed: ExampleTyped = new {
aa { "hello" } // aa = new Listing { "hello" } works fine
bb = "hello"
}
```
**Pkl Error:**
```
– Pkl Error ––
Tried to read property `aa` but its value is undefined.
21 | aa: Listing | String
^^
at example.aa (file:///path/to/example.pkl, line 21)
The above error occurred when rendering path `typed.aa` of module `file:///path/to/example.pkl`.
128 | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (https://github.com/apple/pkl/blob/0.30.1/stdlib/base.pkl#L128)
132 | if (renderer is BytesRenderer) renderer.renderDocument(value) else text.encodeToBytes("UTF-8")
^^^^
at pkl.base#Module.output.bytes (https://github.com/apple/pkl/blob/0.30.1/stdlib/base.pkl#L132)
```
Version: `Pkl 0.30.1 (Linux 6.11.0-1018-azure, native)`
Contributor guide
Research direction
Start by reproducing the Pkl 0.30.1 example with `Listing | String` and compare its behavior with the working `Int` and `String` cases. Trace the undefined-property diagnostic for `typed.aa`; done means the error identifies the failed union-type inference more specifically than the current message.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100