Files
sdk/tests/language/call/method_must_not_be_field_test.dart
T
Robert Nystrom 739852d99d Migrate language_2/call to NNBD.
Change-Id: I3356296e72dfa07b0ac994da0ce96f766b182e80
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/137722
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
2020-03-05 19:56:49 +00:00

30 lines
929 B
Dart

// Copyright (c) 2018, 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.
// Dart test program to test arithmetic operations.
import "package:expect/expect.dart";
class C {
void Function() call = () {};
}
main() {
C c = new C();
dynamic d = c;
// The presence of a field named `call` does not permit the class `C` to be
// implicitly called.
c(); //# 01: compile-time error
// Nor does it permit an implicit tear-off of `call`.
void Function() f = c; //# 02: compile-time error
// Nor does it permit a dynamic invocation of `call`.
Expect.throws(() => d()); //# 03: ok
// However, all these things are possible if `call` is mentioned explicitly.
c.call(); //# 04: ok
void Function() f = c.call; //# 05: ok
d.call(); //# 06: ok
(d.call)(); //# 07: ok
}