diff --git a/Language/Functions/element_type_A01_t01.dart b/Language/Functions/element_type_A01_t01.dart index eac1944583..4b65e4b466 100644 --- a/Language/Functions/element_type_A01_t01.dart +++ b/Language/Functions/element_type_A01_t01.dart @@ -17,6 +17,7 @@ /// `T`, and `S` is of the form `Iterable`, it is a compile-time error to /// yield an expression whose static type isn't assignable to `U`. /// @author sgrekhov22@gmail.com +/// @issue 53054 import "dart:async"; diff --git a/Language/Functions/element_type_A01_t02.dart b/Language/Functions/element_type_A01_t02.dart index 17b39cc4e5..ab72d15c81 100644 --- a/Language/Functions/element_type_A01_t02.dart +++ b/Language/Functions/element_type_A01_t02.dart @@ -17,6 +17,7 @@ /// `T`, and `S` is of the form `Iterable`, it is a compile-time error to /// yield an expression whose static type isn't assignable to `U`. /// @author sgrekhov22@gmail.com +/// @issue 53054 import "dart:async"; diff --git a/Language/Functions/element_type_A02_t01.dart b/Language/Functions/element_type_A02_t01.dart index 26f89b6126..43bb85ac9d 100644 --- a/Language/Functions/element_type_A02_t01.dart +++ b/Language/Functions/element_type_A02_t01.dart @@ -18,6 +18,7 @@ /// `T`, and `S` is of the form `Stream`, it is a compile-time error to /// yield an expression whose static type isn't assignable to `U`. /// @author sgrekhov22@gmail.com +/// @issue 53054 import "dart:async"; diff --git a/Language/Functions/element_type_A02_t02.dart b/Language/Functions/element_type_A02_t02.dart index c1074ddc82..62fa8773ba 100644 --- a/Language/Functions/element_type_A02_t02.dart +++ b/Language/Functions/element_type_A02_t02.dart @@ -18,6 +18,7 @@ /// `T`, and `S` is of the form `Stream`, it is a compile-time error to /// yield an expression whose static type isn't assignable to `U`. /// @author sgrekhov22@gmail.com +/// @issue 53054 import "dart:async"; diff --git a/Language/Functions/function_body_short_syntax_t01.dart b/Language/Functions/function_body_short_syntax_A01_t01.dart similarity index 58% rename from Language/Functions/function_body_short_syntax_t01.dart rename to Language/Functions/function_body_short_syntax_A01_t01.dart index 890c0bfc6a..2c86cc0138 100644 --- a/Language/Functions/function_body_short_syntax_t01.dart +++ b/Language/Functions/function_body_short_syntax_A01_t01.dart @@ -2,20 +2,18 @@ // 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;}. -/// -/// @description Checks that the function body of the form => e is equivalent -/// to a body of the form {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 `=> e` is equivalent +/// to a body of the form `{return e;}`. /// @author msyabro import "../../Utils/expect.dart"; main() { - int x = 2; - foo1() => 1; foo2() {return 1;} bar1(int val) => val * 2; diff --git a/Language/Functions/function_body_short_syntax_t02.dart b/Language/Functions/function_body_short_syntax_A01_t02.dart similarity index 68% rename from Language/Functions/function_body_short_syntax_t02.dart rename to Language/Functions/function_body_short_syntax_A01_t02.dart index 20ce389f45..dd26a9f808 100644 --- a/Language/Functions/function_body_short_syntax_t02.dart +++ b/Language/Functions/function_body_short_syntax_A01_t02.dart @@ -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 a.semenov@unipro.ru import 'dart:async'; diff --git a/Language/Functions/function_body_short_syntax_A02_t01.dart b/Language/Functions/function_body_short_syntax_A02_t01.dart new file mode 100644 index 0000000000..2eab38f79c --- /dev/null +++ b/Language/Functions/function_body_short_syntax_A02_t01.dart @@ -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 sgrekhov22@qmail.com + +import 'dart:async'; + +Stream f1() async* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +Stream f2() async* => [1]; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +Stream f3() async* => Stream.fromIterable([1]); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +Stream f4() async* => 1 as dynamic; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +Stream f5() async* => null; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +Stream f6() async* => print(""); // print("") returns void +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +FutureOr> f7() async* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + +main() { + print(f1); + print(f2); + print(f3); + print(f4); + print(f5); + print(f6); + print(f7); +} diff --git a/Language/Functions/function_body_short_syntax_A02_t02.dart b/Language/Functions/function_body_short_syntax_A02_t02.dart new file mode 100644 index 0000000000..a499c2bb9d --- /dev/null +++ b/Language/Functions/function_body_short_syntax_A02_t02.dart @@ -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 sgrekhov22@qmail.com + +import 'dart:async'; + +Iterable f1() sync* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +Iterable f2() sync* => [1]; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +Iterable f3() sync* => Stream.fromIterable([1]); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +Iterable f4() sync* => 1 as dynamic; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +Iterable f5() sync* => null; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +Iterable f6() sync* => print(""); // print("") returns void +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +FutureOr> f7() sync* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + +main() { + print(f1); + print(f2); + print(f3); + print(f4); + print(f5); + print(f6); + print(f7); +} diff --git a/Language/Functions/function_body_short_syntax_A02_t03.dart b/Language/Functions/function_body_short_syntax_A02_t03.dart new file mode 100644 index 0000000000..32a1c48e1b --- /dev/null +++ b/Language/Functions/function_body_short_syntax_A02_t03.dart @@ -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 sgrekhov22@qmail.com + +import 'dart:async'; + +class C { + static Stream staticMethod() async* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + Stream instanceMethod() async* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + static Stream staticMethod() async* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + Stream instanceMethod() async* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0; + static Stream staticMethod() async* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + Stream instanceMethod() async* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} + +extension Ext on A { + static Stream staticMethod() async* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + Stream instanceMethod() async* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(int _) { + static Stream staticMethod() async* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + Stream instanceMethod() async* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/Language/Functions/function_body_short_syntax_A02_t04.dart b/Language/Functions/function_body_short_syntax_A02_t04.dart new file mode 100644 index 0000000000..1a2a5e72e3 --- /dev/null +++ b/Language/Functions/function_body_short_syntax_A02_t04.dart @@ -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 sgrekhov22@qmail.com + +import 'dart:async'; + +class C { + static Iterable staticMethod() sync* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + Iterable instanceMethod() sync* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + static Iterable staticMethod() sync* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + Iterable instanceMethod() sync* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0; + static Iterable staticMethod() sync* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + Iterable instanceMethod() sync* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} + +extension Ext on A { + static Iterable staticMethod() sync* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + Iterable instanceMethod() sync* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(int _) { + static Iterable staticMethod() sync* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + Iterable instanceMethod() sync* => 1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/Language/Functions/function_body_short_syntax_A03_t01.dart b/Language/Functions/function_body_short_syntax_A03_t01.dart new file mode 100644 index 0000000000..0db1e72b4c --- /dev/null +++ b/Language/Functions/function_body_short_syntax_A03_t01.dart @@ -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 sgrekhov22@qmail.com + +void f1() => 1; +void f2() => null; +void f3(T t) => t; +void f4() => print(""); + +main() { + print(f1); + print(f2); + print(f3); + print(f4); +} diff --git a/Language/Functions/function_body_short_syntax_A03_t02.dart b/Language/Functions/function_body_short_syntax_A03_t02.dart new file mode 100644 index 0000000000..6b5d13fdc3 --- /dev/null +++ b/Language/Functions/function_body_short_syntax_A03_t02.dart @@ -0,0 +1,36 @@ +// 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 a compile-time error to declare a synchronous +/// function with a short syntax and an incompatible return type. +/// @author sgrekhov22@qmail.com + +String f1() => 1; +// ^ +// [analyzer] unspecified +// [cfe] unspecified +int f2() => null; +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified +String f3(T t) => t; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + +main() { + print(f1); + print(f2); + print(f3); +} diff --git a/Language/Functions/function_body_short_syntax_A03_t03.dart b/Language/Functions/function_body_short_syntax_A03_t03.dart new file mode 100644 index 0000000000..1970a559e4 --- /dev/null +++ b/Language/Functions/function_body_short_syntax_A03_t03.dart @@ -0,0 +1,53 @@ +// 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 method +/// with a short syntax and the return type `void`. +/// @author sgrekhov22@qmail.com + +class C { + static void staticMethod() => 1; + void instanceMethod() => 1; +} + +mixin M { + static void staticMethod() => null; + void instanceMethod() => null; +} + +enum E { + e0; + static void staticMethod(T t) => t; + void instanceMethod(T t) => t; +} + +class A {} + +extension Ext on A { + static void staticMethod() => print(""); + void instanceMethod() => print(""); +} + +extension type ET(int _) { + static void staticMethod(T t) => t; + void instanceMethod(T t) => t; +} + +main() { + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/Language/Functions/function_body_short_syntax_A04_t01.dart b/Language/Functions/function_body_short_syntax_A04_t01.dart new file mode 100644 index 0000000000..41b2b4cb4e --- /dev/null +++ b/Language/Functions/function_body_short_syntax_A04_t01.dart @@ -0,0 +1,51 @@ +// 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 asynchronous, `flatten(T)` is not `void`, and it would +/// have been a compile-time error to declare the function with the body +/// `async { return e; }` rather than `async => e`. +/// +/// @description Checks that it is not an error to declare an asynchronous +/// function with return type `T`, with a short syntax and `flatten(T)` is +/// `void`. +/// @author sgrekhov22@qmail.com + +import 'dart:async'; + +void f1() async => 1; +void f2() async => null; +void f3(T t) async => t; +void f4() async => print(""); // print("") returns void + +Future f5() async => 1; +Future f6() async => null; +Future f7(T t) async => t; +Future f8() async => print(""); + +FutureOr f9() async => 1; +FutureOr f10() async => null; +FutureOr f11(T t) async => t; +FutureOr f12() async => print(""); + +main() { + print(f1); + print(f2); + print(f3); + print(f4); + print(f5); + print(f6); + print(f7); + print(f8); + print(f9); + print(f10); + print(f11); + print(f12); +} diff --git a/Language/Functions/function_body_short_syntax_A04_t02.dart b/Language/Functions/function_body_short_syntax_A04_t02.dart new file mode 100644 index 0000000000..4a40dcb34b --- /dev/null +++ b/Language/Functions/function_body_short_syntax_A04_t02.dart @@ -0,0 +1,55 @@ +// 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 asynchronous, `flatten(T)` is not `void`, and it would +/// have been a compile-time error to declare the function with the body +/// `async { return e; }` rather than `async => e`. +/// +/// @description Checks that it is a compile-time error to declare an +/// asynchronous function with a short syntax and an incompatible return type. +/// @author sgrekhov22@qmail.com + +import 'dart:async'; + +Future f1() async => 1; +// ^ +// [analyzer] unspecified +// [cfe] unspecified +Future f2() async => null; +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified +Future f3(T t) async => t; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + +FutureOr f4() async => 1; +// ^ +// [analyzer] unspecified +// [cfe] unspecified +FutureOr f5() async => null; +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified +FutureOr f6(T t) async => t; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + +main() { + print(f1); + print(f2); + print(f3); + print(f4); + print(f5); + print(f6); +} diff --git a/Language/Functions/function_body_short_syntax_A04_t03.dart b/Language/Functions/function_body_short_syntax_A04_t03.dart new file mode 100644 index 0000000000..e8c75d92c6 --- /dev/null +++ b/Language/Functions/function_body_short_syntax_A04_t03.dart @@ -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`. ... 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 asynchronous, `flatten(T)` is not `void`, and it would +/// have been a compile-time error to declare the function with the body +/// `async { return e; }` rather than `async => e`. +/// +/// @description Checks that it is not an error to declare an asynchronous +/// method with return type `T`, with a short syntax and `flatten(T)` is `void`. +/// @author sgrekhov22@qmail.com + +import 'dart:async'; + +class C { + static void staticMethod() async => 1; + void instanceMethod() async => 1; +} + +mixin M { + static void staticMethod() async => null; + void instanceMethod() async => null; +} + +enum E { + e0; + static void staticMethod(T t) async => t; + void instanceMethod(T t) async => t; +} + +class A {} + +extension Ext on A { + static void staticMethod() async => print(""); + void instanceMethod() async => print(""); +} + +extension type ET(int _) { + static void staticMethod(T t) async => t; + void instanceMethod(T t) async => t; +} + +main() { + print(C); + print(M); + print(E); + print(A); + print(ET); +}