Skip to content

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

Open
@HT154

Description

@HT154

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`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions