Overridden properties in subclasses can change the type of the property
- Dominant language
- Java
- Stars
- 11.5k
- Forks
- 402
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 20
Description
Reproduced with Pkl 0.29.0.
Reproducer:
```pkl
open class Foo {
foo: Int
}
class Bar extends Foo {
foo = "foo"
}
output {
value = new Bar {}
}
```
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:
```pkl
open class BaseThing {
// This will be exposed on the final JSON/YAML/etc. output so that code consuming this value can know what type it's dealing with.
fixed type: String
}
class DerivedThing extends BaseThing {
fixed type = 123 // Allowed right now
}
```
Right now derived classes can set `type` to 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 `UnknownType` unless explicitly specified (which causes code generator sadness).
Contributor guide
Research direction
Start by running the supplied Pkl 0.29.0 reproducer and examining the subclass property-override behavior. Determine the intended rules for overridden field types, documentation, and reflection, including what schema authors can do to prevent changes; done means the semantics and code-generation behavior are clearly defined.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100