-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add more tests for functions with a short body. Note that Language/Functions/function_body_short_syntax_A02_t0{1,2,3,4}.dart have intentional syntax errors.
- Loading branch information
Showing
16 changed files
with
574 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
/// `T`, and `S` is of the form `Iterable<U>`, it is a compile-time error to | ||
/// yield an expression whose static type isn't assignable to `U`. | ||
/// @author [email protected] | ||
/// @issue 53054 | ||
import "dart:async"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
/// `T`, and `S` is of the form `Iterable<U>`, it is a compile-time error to | ||
/// yield an expression whose static type isn't assignable to `U`. | ||
/// @author [email protected] | ||
/// @issue 53054 | ||
import "dart:async"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
/// `T`, and `S` is of the form `Stream<U>`, it is a compile-time error to | ||
/// yield an expression whose static type isn't assignable to `U`. | ||
/// @author [email protected] | ||
/// @issue 53054 | ||
import "dart:async"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
/// `T`, and `S` is of the form `Stream<U>`, it is a compile-time error to | ||
/// yield an expression whose static type isn't assignable to `U`. | ||
/// @author [email protected] | ||
/// @issue 53054 | ||
import "dart:async"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,13 @@ | |
// 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. | ||
|
||
/// @assertion A function body of the form => e is equivalent to a body of | ||
/// the form {return e;} or the form async => e which is equivalent to a body | ||
/// of the form async {return e;}. | ||
/// @assertion A function body is either: | ||
/// ... | ||
/// - of the form `=> e` or the form `async => e`, which both return the value | ||
/// of the expression `e` as if by a `return e`. | ||
/// | ||
/// @description Checks that the function body of the form async => e is | ||
/// equivalent to a body of the form async {return e;}. | ||
/// @description Checks that the function body of the form `async => e` is | ||
/// equivalent to a body of the form `async {return e;}`. | ||
/// @author [email protected] | ||
import 'dart:async'; | ||
|
56 changes: 56 additions & 0 deletions
56
Language/Functions/function_body_short_syntax_A02_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
/// @assertion A function body is either: | ||
/// ... | ||
/// - of the form `=> e` or the form `async => e`, which both return the value | ||
/// of the expression `e` as if by a `return e`. The other modifiers do not | ||
/// apply here, because they apply only to generators, discussed below. | ||
/// Generators are not allowed to explicitly return anything, objects are | ||
/// added to the generated stream or iterable using `yield` or `yield*`. | ||
/// | ||
/// @description Checks that it is a compile-time error if a function with a | ||
/// short syntax contains `async*` modifier. | ||
/// @author [email protected] | ||
import 'dart:async'; | ||
|
||
Stream<int> f1() async* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Stream<int> f2() async* => [1]; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Stream<int> f3() async* => Stream.fromIterable([1]); | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Stream<void> f4() async* => 1 as dynamic; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Stream<void> f5() async* => null; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Stream<void> f6() async* => print(""); // print("") returns void | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
FutureOr<Stream<int>> f7() async* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
main() { | ||
print(f1); | ||
print(f2); | ||
print(f3); | ||
print(f4); | ||
print(f5); | ||
print(f6); | ||
print(f7); | ||
} |
56 changes: 56 additions & 0 deletions
56
Language/Functions/function_body_short_syntax_A02_t02.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
/// @assertion A function body is either: | ||
/// ... | ||
/// - of the form `=> e` or the form `async => e`, which both return the value | ||
/// of the expression `e` as if by a `return e`. The other modifiers do not | ||
/// apply here, because they apply only to generators, discussed below. | ||
/// Generators are not allowed to explicitly return anything, objects are | ||
/// added to the generated stream or iterable using `yield` or `yield*`. | ||
/// | ||
/// @description Checks that it is a compile-time error if a function with a | ||
/// short syntax contains `sync*` modifier. | ||
/// @author [email protected] | ||
import 'dart:async'; | ||
|
||
Iterable<int> f1() sync* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Iterable<int> f2() sync* => [1]; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Iterable<int> f3() sync* => Stream.fromIterable([1]); | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Iterable<void> f4() sync* => 1 as dynamic; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Iterable<void> f5() sync* => null; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Iterable<void> f6() sync* => print(""); // print("") returns void | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
FutureOr<Iterable<int>> f7() sync* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
main() { | ||
print(f1); | ||
print(f2); | ||
print(f3); | ||
print(f4); | ||
print(f5); | ||
print(f6); | ||
print(f7); | ||
} |
83 changes: 83 additions & 0 deletions
83
Language/Functions/function_body_short_syntax_A02_t03.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
/// @assertion A function body is either: | ||
/// ... | ||
/// - of the form `=> e` or the form `async => e`, which both return the value | ||
/// of the expression `e` as if by a `return e`. The other modifiers do not | ||
/// apply here, because they apply only to generators, discussed below. | ||
/// Generators are not allowed to explicitly return anything, objects are | ||
/// added to the generated stream or iterable using `yield` or `yield*`. | ||
/// | ||
/// @description Checks that it is a compile-time error if a method with a | ||
/// short syntax contains `async*` modifier. | ||
/// @author [email protected] | ||
import 'dart:async'; | ||
|
||
class C { | ||
static Stream<int> staticMethod() async* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Stream<int> instanceMethod() async* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
mixin M { | ||
static Stream<int> staticMethod() async* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Stream<int> instanceMethod() async* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
enum E { | ||
e0; | ||
static Stream<int> staticMethod() async* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Stream<int> instanceMethod() async* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
class A {} | ||
|
||
extension Ext on A { | ||
static Stream<int> staticMethod() async* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Stream<int> instanceMethod() async* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
extension type ET(int _) { | ||
static Stream<int> staticMethod() async* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Stream<int> instanceMethod() async* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
print(C); | ||
print(M); | ||
print(E); | ||
print(A); | ||
print(ET); | ||
} |
83 changes: 83 additions & 0 deletions
83
Language/Functions/function_body_short_syntax_A02_t04.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
/// @assertion A function body is either: | ||
/// ... | ||
/// - of the form `=> e` or the form `async => e`, which both return the value | ||
/// of the expression `e` as if by a `return e`. The other modifiers do not | ||
/// apply here, because they apply only to generators, discussed below. | ||
/// Generators are not allowed to explicitly return anything, objects are | ||
/// added to the generated stream or iterable using `yield` or `yield*`. | ||
/// | ||
/// @description Checks that it is a compile-time error if a method with a | ||
/// short syntax contains `sync*` modifier. | ||
/// @author [email protected] | ||
import 'dart:async'; | ||
|
||
class C { | ||
static Iterable<int> staticMethod() sync* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Iterable<int> instanceMethod() sync* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
mixin M { | ||
static Iterable<int> staticMethod() sync* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Iterable<int> instanceMethod() sync* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
enum E { | ||
e0; | ||
static Iterable<int> staticMethod() sync* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Iterable<int> instanceMethod() sync* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
class A {} | ||
|
||
extension Ext on A { | ||
static Iterable<int> staticMethod() sync* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Iterable<int> instanceMethod() sync* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
extension type ET(int _) { | ||
static Iterable<int> staticMethod() sync* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
Iterable<int> instanceMethod() sync* => 1; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
print(C); | ||
print(M); | ||
print(E); | ||
print(A); | ||
print(ET); | ||
} |
29 changes: 29 additions & 0 deletions
29
Language/Functions/function_body_short_syntax_A03_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
/// @assertion A function body is either: | ||
/// ... | ||
/// - of the form `=> e` or the form `async => e`, which both return the value | ||
/// of the expression `e` as if by a `return e`. ... Let `T` be the declared | ||
/// return type of the function that has this body. It is a compile-time error | ||
/// if one of the following conditions hold: | ||
/// – The function is synchronous, `T` is not `void`, and it would have been a | ||
/// compile-time error to declare the function with the body `{ return e; }` | ||
/// rather than `=> e`. | ||
/// | ||
/// @description Checks that it is not an error to declare a synchronous | ||
/// function with a short syntax and the return type `void`. | ||
/// @author [email protected] | ||
void f1() => 1; | ||
void f2() => null; | ||
void f3<T>(T t) => t; | ||
void f4() => print(""); | ||
|
||
main() { | ||
print(f1); | ||
print(f2); | ||
print(f3); | ||
print(f4); | ||
} |
Oops, something went wrong.