dart-sdk/tests/language/regress/regress36084_test.dart
Robert Nystrom 67539c2faf Migrate language_2/regress to NNBD.
Change-Id: I318742cd4303d70c0625c9efd98bb01087aa5de4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150466
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
2020-06-13 01:00:22 +00:00

63 lines
1.5 KiB
Dart

// Copyright (c) 2019, 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";
class A {
void call(int a, [int b = -1]) {}
}
class A1 {
void call(int a, [int b = -1]) {}
int noSuchMethod(Invocation invocation) {
return 42;
}
}
class A2 {
// Same as A1 but without a call method.
int noSuchMethod(Invocation invocation) {
return 42;
}
}
class B {
dynamic foo;
dynamic get bar => foo;
}
class B1 {
dynamic foo;
dynamic get bar => foo;
noSuchMethod(Invocation invocation) {
Expect.fail('B1.noSuchMethod should not be called.');
}
}
main() {
B b = new B();
b.foo = new A();
Expect.throwsNoSuchMethodError(() => b.foo(1, 2, 3));
Expect.throwsNoSuchMethodError(() => b.bar(1, 2, 3));
b.foo = new A1();
Expect.equals(42, b.foo(1, 2, 3));
Expect.equals(42, b.bar(1, 2, 3));
b.foo = new A2();
Expect.equals(42, b.foo(1, 2, 3));
Expect.equals(42, b.bar(1, 2, 3));
// Same test but with B1, which has its own `noSuchMethod()` handler.
B1 b1 = new B1();
b1.foo = new A();
Expect.throwsNoSuchMethodError(() => b1.foo(1, 2, 3));
Expect.throwsNoSuchMethodError(() => b1.bar(1, 2, 3));
b1.foo = new A1();
Expect.equals(42, b1.foo(1, 2, 3));
Expect.equals(42, b1.bar(1, 2, 3));
b1.foo = new A2();
Expect.equals(42, b1.foo(1, 2, 3));
Expect.equals(42, b1.bar(1, 2, 3));
}