Skip to content

Amending an undefined property with a union type with no default member should produce a more specific error #1368

@joshqou

Description

@joshqou

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:

class ExampleTyped {
    aa: Listing<String> | 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> | 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions