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

Open
opened 2025-12-30 01:23:20 +01:00 by adam · 1 comment
Owner

Originally created by @HT154 on GitHub (Apr 21, 2025).

It's weird that this does not produce an error:

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.

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`.
Originally created by @HT154 on GitHub (Apr 21, 2025). 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`. ```
Author
Owner

@bioball commented on GitHub (Apr 22, 2025):

We definitely want to improve this, but it's not as simple as "lookup on a Typed should fail". A module is also a Typed, and this syntax should still work:

foo {
  res = 1
}
@bioball commented on GitHub (Apr 22, 2025): We definitely want to improve this, but it's not as simple as "lookup on a `Typed` should fail". A module is also a `Typed`, and this syntax should still work: ``` foo { res = 1 } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#306