Skip to content

Extensions can't shadow members, leading to unexpected behaviour changes #966

Open
@Hixie

Description

@Hixie

Suppose a library declares a type Foo:

class Foo { }

...and an application uses it alongside an extension:

import 'library.dart';

extension on Object {
  void test() {
    print("on Object");
  }
}

void main() {
  Object().test();
  Foo().test();
  Object o = Foo();
  o.test();
  Foo f = o;
  f.test();
}

This prints "on Object" four times.

Now, the following supposedly non-breaking change is made and the library is revved:

class Foo { 
  void test() {
    print("hello from Foo");
  }
}

The next time the above application is run, the output is now "on Object", "hello from Foo", "on Object", "hello from Foo", instead of "on Object" four times.

It seems like an extension should shadow members, or that the same "can't import two conflicting names" logic we have for imported members should apply here, or something.

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