e9ca413263
Closes #41349 Closes #41495 Change-Id: I1893502592af1615184b5dd294e1835b51959a07 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144761 Reviewed-by: Dmitry Stefantsov <dmitryas@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com>
42 lines
981 B
Dart
42 lines
981 B
Dart
// Copyright (c) 2020, 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.
|
|
|
|
class A {
|
|
foo() => 23;
|
|
}
|
|
|
|
extension B on A? {
|
|
foo() => 42;
|
|
bar() => 87;
|
|
}
|
|
|
|
extension C on A {
|
|
bar() => 123;
|
|
}
|
|
|
|
extension D on int Function()? {
|
|
int call() => 76;
|
|
}
|
|
|
|
main() {
|
|
testA(new A());
|
|
testFunction(() => 53);
|
|
}
|
|
|
|
testA(A? a) {
|
|
expect(23, a?.foo()); // A.foo instead of B.foo.
|
|
expect(42, a.foo()); // B.foo instead of nullable access to A.foo.
|
|
expect(123, a?.bar()); // C.bar instead of B.bar.
|
|
expect(87, a.bar()); // B.bar instead of nullable access to C.bar.
|
|
}
|
|
|
|
testFunction(int Function()? f) {
|
|
expect(53, f?.call()); // Function.call instead of D.call.
|
|
expect(76, f.call()); // D.call instead of nullable access to Function.call.
|
|
}
|
|
|
|
expect(expected, actual) {
|
|
if (expected != actual) throw 'Expected $expected, actual $actual';
|
|
}
|