Skip to content

Commit 80d05e0

Browse files
authored
Fixes #2505. Add more tests for call member (#2506)
Add more tests for `call` member. Co-authored-by: Erik Ernst <[email protected]>: Changed wording in `@description` slightly, because the invocation doesn't call `call` explicitly.
1 parent 9e9e32c commit 80d05e0

File tree

8 files changed

+260
-7
lines changed

8 files changed

+260
-7
lines changed

Language/Expressions/Function_Invocation/Function_Expression_Invocation/invocation_t02.dart renamed to Language/Expressions/Function_Invocation/Function_Expression_Invocation/call_A01_t01.dart

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion A function expression invocation
6-
/// ef(a1, ..., an, xn+1: an+1, ..., xn+k: an+k) is equivalent to
7-
/// ef.call(a1, ..., an, xn+1: an+1, ..., xn+k: an+k).
5+
/// @assertion A function expression invocation i has the form
6+
/// ef <A1, . . . , Ar>(a1, . . . , an, xn+1: an+1, . . . , xn+k: an+k),
7+
/// where ef is an expression.
8+
/// ...
9+
/// Let F be the static type of ef . If F is an interface type that has a method
10+
/// named call, i is treated as the ordinary invocation
11+
/// ef .call<A1, . . . , Ar>(a1, . . . , an, xn+1: an+1, . . . , xn+k: an+k)
12+
///
813
/// @description Checks that a function expression invocation ef(...) is indeed
9-
/// equivalent to the ordinary method invocation ef.call(...) and that the result
10-
/// in either case is the same as expected whether ef is a function literal
11-
/// expression or some other kind of expression.
14+
/// equivalent to the ordinary method invocation ef.call(...) and that the
15+
/// result in either case is the same as expected whether ef is a function
16+
/// literal expression or some other kind of expression.
1217
/// @author rodionov
1318
1419
import '../../../../Utils/expect.dart';
@@ -21,7 +26,6 @@ class C {
2126

2227
main() {
2328
C c = new C();
24-
2529
Expect.equals("call(1, foo)", c(1));
2630
Expect.equals("call(2, bar)", c(2, "bar"));
2731
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion A function expression invocation i has the form
6+
/// ef <A1, . . . , Ar>(a1, . . . , an, xn+1: an+1, . . . , xn+k: an+k),
7+
/// where ef is an expression.
8+
/// ...
9+
/// Let F be the static type of ef . If F is an interface type that has a method
10+
/// named call, i is treated as the ordinary invocation
11+
/// ef .call<A1, . . . , Ar>(a1, . . . , an, xn+1: an+1, . . . , xn+k: an+k)
12+
///
13+
/// @description Checks that an interface containing a `call` method is
14+
/// assignable to the type `Function`
15+
/// @author [email protected]
16+
17+
import '../../../../Utils/expect.dart';
18+
19+
class C {
20+
int call() => 1;
21+
}
22+
23+
enum E {
24+
e1, e2;
25+
26+
int call() => 2;
27+
}
28+
29+
mixin M {
30+
int call() => 3;
31+
}
32+
33+
class MA = Object with M;
34+
35+
main() {
36+
Function f1 = C();
37+
Function f2 = E.e1;
38+
Function f3 = MA();
39+
40+
Expect.equals(1, f1());
41+
Expect.equals(2, f2());
42+
Expect.equals(3, f3());
43+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion A function expression invocation i has the form
6+
/// ef <A1, . . . , Ar>(a1, . . . , an, xn+1: an+1, . . . , xn+k: an+k),
7+
/// where ef is an expression.
8+
/// ...
9+
/// Let F be the static type of ef . If F is an interface type that has a method
10+
/// named call, i is treated as the ordinary invocation
11+
/// ef .call<A1, . . . , Ar>(a1, . . . , an, xn+1: an+1, . . . , xn+k: an+k)
12+
///
13+
/// @description Checks that an interface containing a `call` getter is not
14+
/// assignable to the type `Function`
15+
/// @author [email protected]
16+
17+
class C {
18+
int get call => 1;
19+
}
20+
21+
enum E {
22+
e1, e2;
23+
24+
int get call => 2;
25+
}
26+
27+
mixin M {
28+
int get call => 3;
29+
}
30+
31+
class MA = Object with M;
32+
33+
main() {
34+
Function f1 = C();
35+
// ^^^
36+
// [analyzer] unspecified
37+
// [cfe] unspecified
38+
Function f2 = E.e1;
39+
// ^^^^
40+
// [analyzer] unspecified
41+
// [cfe] unspecified
42+
Function f3 = MA();
43+
// ^^^^
44+
// [analyzer] unspecified
45+
// [cfe] unspecified
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion A function expression invocation i has the form
6+
/// ef <A1, . . . , Ar>(a1, . . . , an, xn+1: an+1, . . . , xn+k: an+k),
7+
/// where ef is an expression.
8+
/// ...
9+
/// Let F be the static type of ef . If F is an interface type that has a method
10+
/// named call, i is treated as the ordinary invocation
11+
/// ef .call<A1, . . . , Ar>(a1, . . . , an, xn+1: an+1, . . . , xn+k: an+k)
12+
///
13+
/// @description Checks that an interface containing a `call` setter is not
14+
/// assignable to the type `Function`
15+
/// @author [email protected]
16+
17+
class C {
18+
void set call(int _) {}
19+
}
20+
21+
enum E {
22+
e1, e2;
23+
24+
void set call(int _) {}
25+
}
26+
27+
mixin M {
28+
void set call(int _) {}
29+
}
30+
31+
class MA = Object with M;
32+
33+
main() {
34+
Function f1 = C();
35+
// ^^^
36+
// [analyzer] unspecified
37+
// [cfe] unspecified
38+
Function f2 = E.e1;
39+
// ^^^^
40+
// [analyzer] unspecified
41+
// [cfe] unspecified
42+
Function f3 = MA();
43+
// ^^^^
44+
// [analyzer] unspecified
45+
// [cfe] unspecified
46+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion A function expression invocation i has the form
6+
/// ef <A1, . . . , Ar>(a1, . . . , an, xn+1: an+1, . . . , xn+k: an+k),
7+
/// where ef is an expression.
8+
/// ...
9+
/// Let F be the static type of ef . If F is an interface type that has a method
10+
/// named call, i is treated as the ordinary invocation
11+
/// ef .call<A1, . . . , Ar>(a1, . . . , an, xn+1: an+1, . . . , xn+k: an+k)
12+
///
13+
/// @description Checks an implicit tear off `call` from a receiver whose type
14+
/// is a type variable
15+
/// @author [email protected]
16+
17+
import '../../../../Utils/expect.dart';
18+
import '../../../../Utils/static_type_helper.dart';
19+
20+
class A {
21+
int call() => 42;
22+
}
23+
24+
Function f<X extends A>(X x) => x;
25+
26+
void main() {
27+
f(A()).expectStaticType<Exactly<Function>>();
28+
Expect.equals(42, f(A())());
29+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion A function expression invocation i has the form
6+
/// ef <A1, . . . , Ar>(a1, . . . , an, xn+1: an+1, . . . , xn+k: an+k),
7+
/// where ef is an expression.
8+
/// ...
9+
/// Let F be the static type of ef . If F is an interface type that has a method
10+
/// named call, i is treated as the ordinary invocation
11+
/// ef .call<A1, . . . , Ar>(a1, . . . , an, xn+1: an+1, . . . , xn+k: an+k)
12+
///
13+
/// @description Checks that it is a compile-time error to assign an implicit
14+
/// tear off a `call` getter or setter to the type `Function`
15+
/// @author [email protected]
16+
17+
class A {
18+
int get call => 42;
19+
}
20+
21+
class B {
22+
void set call(int _) {}
23+
}
24+
25+
Function f1<X extends A>(X x) => x;
26+
// ^
27+
// [analyzer] unspecified
28+
// [cfe] unspecified
29+
Function f2<X extends B>(X x) => x;
30+
// ^
31+
// [analyzer] unspecified
32+
// [cfe] unspecified
33+
34+
void main() {
35+
print(f1);
36+
print(f2);
37+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion A function expression invocation i has the form
6+
/// ef <A1, . . . , Ar>(a1, . . . , an, xn+1: an+1, . . . , xn+k: an+k),
7+
/// where ef is an expression.
8+
/// ...
9+
/// Let F be the static type of ef . If F is an interface type that has a method
10+
/// named call, i is treated as the ordinary invocation
11+
/// ef .call<A1, . . . , Ar>(a1, . . . , an, xn+1: an+1, . . . , xn+k: an+k)
12+
///
13+
/// @description Checks that a record with a `call` member is not assignable to
14+
/// the type `Function`
15+
/// @author [email protected]
16+
17+
void main() {
18+
var r = (call: () => 42);
19+
Function f = r;
20+
// ^
21+
// [analyzer] unspecified
22+
// [cfe] unspecified
23+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion A function expression invocation i has the form
6+
/// ef <A1, . . . , Ar>(a1, . . . , an, xn+1: an+1, . . . , xn+k: an+k),
7+
/// where ef is an expression.
8+
/// ...
9+
/// Let F be the static type of ef . If F is an interface type that has a method
10+
/// named call, i is treated as the ordinary invocation
11+
/// ef .call<A1, . . . , Ar>(a1, . . . , an, xn+1: an+1, . . . , xn+k: an+k)
12+
///
13+
/// @description Checks that it is a compile-time error to invoke a record
14+
/// that has a getter named `call`.
15+
/// @author [email protected]
16+
/// @issue 54616,54651
17+
18+
void main() {
19+
var r = (call: () => 42);
20+
r();
21+
//^^^
22+
// [analyzer] unspecified
23+
// [cfe] unspecified
24+
r.call(); // Ok
25+
}

0 commit comments

Comments
 (0)