mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Overridden properties in subclasses can change the type of the property #336
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 @sin-ack on GitHub (Aug 8, 2025).
Reproduced with Pkl 0.29.0.
Reproducer:
This is more of a clarification question: Should this be allowed? As a follow-up, what should one do if they don't want this to be allowed in their schema? My use-case is the following:
Right now derived classes can set
typeto anything, which causes chaos.Follow-up to the follow-up: In case of property overrides in subclasses, should aspects of the property like documentation and field type be preserved? Right now, if one specifies the type on the superclass and reflects the subclass, the type of the overridden field will be
UnknownTypeunless explicitly specified (which causes code generator sadness).@bioball commented on GitHub (Aug 8, 2025):
At the moment, Pkl will allow you to override the type of a property with no restrictions.
This is something that we'd like to change in the future, but it needs some thinking through.
From a type perspective, it's only sound to override the type of a property if:
fixedorconst(only output properties should be overridable)Sidenote: possibly we should only enforce rule 1, but not 2. This is a more pragmatic approach for Pkl.
However, right now, Pkl doesn't understand what a subtype is. We have some initial ideas for how to implement this, but nothing concrete right now.
By the way, both snippets that you've posted are errors. Because the child property doesn't declare a type, the property's type is not actually overridden. They both result in this error: