mirror of
https://github.com/apple/pkl.git
synced 2026-01-13 15:13:38 +01:00
Amending an undefined property with a union type with no default member should produce a more specific error #371
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @joshqou on GitHub (Dec 13, 2025).
When a field is typed as
ListingorString, Pkl will fail to intuit the type of the value if it inherits from Dynamic.Intwill also be intuited correctly, whereasMappingis also not intuited.Example:
Pkl Error:
Version:
Pkl 0.30.1 (Linux 6.11.0-1018-azure, native)@HT154 commented on GitHub (Dec 13, 2025):
This is actually expected behavior! This is the error you get when you attempt to amend a type with no default value.
This error message doesn't seem like the best for this situation, so I think it's worth keeping this issue open to explore if a better error can be produced in this scenario.
Here's what's actually happening here:
Union types have no implicit default type (and therefore no default value to amend). This is why assigning a value to the property (regardless of type) doesn't error.
You can annotate union types with
*to specify a default member. Amending a property that has a union type with a default is equivalent to amending that default. Typically, when a union type consists of anObjectsubclass likeListingand a non-Objecttype likeString, you should select theObjecttype as the default.This code exhibits the behavior you're expecting:
In simple cases like this, Pkl might—in theory—be able to intelligently choose a default union member, but it's not possible to do so in all cases, so we require this behavior to be explicitly specified for consistency.