dart-sdk/tests/language/no_such_method/no_such_method2_test.dart
Robert Nystrom 65032b4e4e Migrate language_2/no_such_method to NNBD.
Change-Id: I5bae11c115c7ee2c9a581ce71f2d29203b92f923
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149783
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2020-06-03 17:15:10 +00:00

48 lines
1.3 KiB
Dart

// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
// Regression test for https://code.google.com/p/dart/issues/detail?id=7697.
// dart2js used to optimize [noSuchMethod] based on the user-provided
// argument, and forget that the runtime might call it with its own
// [Invocation] implementation.
class Hey {
foo() => noSuchMethod(new FakeInvocationMirror());
noSuchMethod(x) => x;
}
class You extends Hey {
// We used to think this method is always called with a
// FakeInvocationMirror instance, but it's also called with the
// internal mirror implementation.
noSuchMethod(x) => x.isGetter;
}
class FakeInvocationMirror extends Invocation {
final bool isGetter = false;
@override
bool get isMethod => false;
@override
bool get isSetter => false;
@override
Symbol get memberName => Symbol('fake');
@override
Map<Symbol, dynamic> get namedArguments => {};
@override
List get positionalArguments => [];
}
main() {
var x = new Hey();
Expect.isTrue(x.foo() is FakeInvocationMirror);
var y = [new You() as dynamic];
Expect.isTrue(y[0].bar);
}