apple / apple/pkl

Amending an undefined property via `super` member access always amends `new Dynamic {}`

Open
#1,046 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
11.5k
Forks
402
Avg merge
1d 15h
Merged PRs (30d)
20

Description

It's weird that this does not produce an error:
```pkl
abstract class Bird {
name: String
}

class Parrot extends Bird {
name = "Polly"
lifespan = (super.lifespan) { // Bird does not define a property lifespan
min = 5
max = 20
}
}

mybird = new Parrot {}
```

Adding a `trace()` around `super.lifespan` indicates this expression has value `new Dynamic {}`.

This behavior makes sense in dynamic context where the parent may not define properties the child needs to amend, eg.
```pkl
foo { // this is in module definition context
bar { // this is in Dynamic object body context
baz = true
}
}
// which is syntax sugar for:
foo = (super.foo) {
bar = (super.bar) {
baz = true
}
}
```

But in a typed context where the full set of properties of the parent is known, attempting to access an unknown property should result in an error like this:
```
Cannot find property `lifespan` in object of type `bird#Bird`.
```

Contributor guide

Open the contributing guide

Research direction

Start by running the Pkl reproduction in the issue and tracing the value of super.lifespan in the typed Parrot context. Compare that behavior with dynamic object-body amendment, then identify where unknown typed-property access is handled. Done means the example reports the expected missing-property error while the dynamic-context example still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.