dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.3k stars 1.59k forks source link

Implement NSM forwarders for private methods on interface implementation #34985

Open vsmenon opened 6 years ago

vsmenon commented 6 years ago

See #34962 for deeper discussion from @lrhn and @eernstg. The following behaves inconsistently on various implementations.

For:

foo.dart:

class Foo {
  int _x = 42;
}

void test(Foo f) {
  print(f._x);
}

bar.dart:

import 'foo.dart';

class Bar implements Foo {
}

void main() {
  var b = new Bar();
  test(b);
}

the proposal is to create NSM forwarders on Bar:

  int get foo::_x => this.noSuchMethod(Invocation.getter(#foo::_x);
  void set foo::_x(int $) => this.noSuchmethod(Invocation.setter(#foo::_x, $);
vsmenon commented 6 years ago

@kmillikin - is this something we can fix in the just the front end?

@mraleph - fyi - the AOT compiler might crash on the above. We have a soundness issue without the forwarders.