Skip to content

Overriding an abstract getter with a final field generates incorrect code #280

Closed
@jmesserly

Description

@jmesserly

We're using this pattern in the compiler:

class VarMember {
  abstract String get name();
  ...
}

class VarFunctionStub extends VarMember {
  final String name;
  ...
}

The code generated for this is incorrect. It tries to create a "name" property on VarMember, which looks like:
Object.defineProperty(VarMember.prototype, "name", {
  get: VarMember.prototype.get$name,
});
Except get$name doesn't exist on the base class. Also, this prevents the setters on the derived classes from working (e.g. "this.name = name;" in VarFunctionStub ctor).

At this point you might be wondering: why isn't the self-hosted compiler currently broken? It is not broken! Probably because we don't use ".name" dynamically. This bug is only triggered when the compiler is used in the same codebase as DOM (or html?) libraries.

Activity

vsmenon

vsmenon commented on Nov 10, 2011

@vsmenon
Member

I'm seeing similar problems when the getter is not abstract:

class A {
  int get x() => null;
}

class B extends A {
  int x;
}

Setting the value x in the derived class is not working for me.

dgrove

dgrove commented on Nov 29, 2011

@dgrove
Contributor

Added this to the FrogEditor milestone.

dgrove

dgrove commented on Nov 30, 2011

@dgrove
Contributor

as of r1908, both of these examples are working correctly.


Added Fixed label.

added this to the FrogEditor milestone on Nov 30, 2011
added a commit that references this issue on Aug 31, 2016
74c7600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Overriding an abstract getter with a final field generates incorrect code · Issue #280 · dart-lang/sdk