Skip to content

Commit

Permalink
#2138. Fix assertions in some functions tests (#2140)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov authored Jul 18, 2023
1 parent 862d8f0 commit ed5f316
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 86 deletions.
12 changes: 7 additions & 5 deletions Language/Functions/Type_of_a_Function/return_type_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +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 If a function does not declare a return type explicitly, its
/// return type is dynamic, unless it is a constructor function, in which case
/// its return type is the immediately enclosing class.
/// @description Checks that return type is dynamic. Static checker should not
/// cause static warnings because type Dynamic has every method and property.
/// @assertion If a function declaration does not declare a return type
/// explicitly, its return type is dynamic, unless it is a constructor, in which
/// case it is not considered to have a return type, or it is a setter or
/// operator []=, in which case its return type is void
///
/// @description Checks that if a function declaration does not declare a return
/// type then its return type is dynamic
/// @author msyabro
import "../../../Utils/expect.dart";
Expand Down
8 changes: 5 additions & 3 deletions Language/Functions/Type_of_a_Function/return_type_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// 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 If a function does not declare a return type explicitly, its
/// return type is dynamic, unless it is a constructor function, in which case
/// its return type is the immediately enclosing class.
/// @assertion If a function declaration does not declare a return type
/// explicitly, its return type is dynamic, unless it is a constructor, in which
/// case it is not considered to have a return type, or it is a setter or
/// operator []=, in which case its return type is void
///
/// @description Checks that return type of a constructor is the immediately
/// enclosing class.
/// @author ngl@unipro.ru
Expand Down
24 changes: 24 additions & 0 deletions Language/Functions/Type_of_a_Function/return_type_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2023, 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 If a function declaration does not declare a return type
/// explicitly, its return type is dynamic, unless it is a constructor, in which
/// case it is not considered to have a return type, or it is a setter or
/// operator []=, in which case its return type is void
///
/// @description Checks that return type of a constructor is the immediately
/// enclosing class.
/// @author sgrekhov22@gmail.com
import "../../../Utils/static_type_helper.dart";

class C {
C() {}
C.n() {}
}

main() {
C.new.expectStaticType<Exactly<C Function()>>();
C.n.expectStaticType<Exactly<C Function()>>();
}
8 changes: 3 additions & 5 deletions Language/Functions/async_return_type_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +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 It is a static warning if the declared return type of a function
/// marked async may not be assigned to Future.
/// @assertion It is a compile-time error if the declared return type of a
/// function marked async is not a supertype of Future<T> for some type T
///
/// @description Check that it is a compile time error, if the declared
/// return type of asynchronous function may not be assigned to Future.
///
/// return type of asynchronous function may not be assigned to `Future`.
/// @author a.semenov@unipro.ru

int f() async {
//^
// [analyzer] unspecified
Expand Down
8 changes: 3 additions & 5 deletions Language/Functions/async_return_type_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +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 It is a static warning if the declared return type of a function
/// marked async may not be assigned to Future.
/// @assertion It is a compile-time error if the declared return type of a
/// function marked async is not a supertype of Future<T> for some type T
///
/// @description Check that it is no compile time error, if the declared
/// return type of asynchronous function may not be assigned to Future but is
/// void.
/// return type of asynchronous function is `void`.
/// @author a.semenov@unipro.ru

void h() async {
return null;
}
Expand Down
14 changes: 9 additions & 5 deletions Language/Functions/async_return_type_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
// 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 It is a static warning if the declared return type of a function
/// marked async may not be assigned to Future.
/// @assertion It is a compile-time error if the declared return type of a
/// function marked async is not a supertype of Future<T> for some type T
///
/// @description Check that it is no compile time error, if the declared
/// return type of asynchronous function may be assigned to Future.
///
/// return type of asynchronous function is a supertype of `Future<T>`
/// @author a.semenov@unipro.ru
import 'dart:async';
Expand All @@ -16,11 +15,16 @@ dynamic a() async {
return 'a';
}

Future b() async {
Future<String> b() async {
return 'b';
}

Future<Never> c() async {
return throw 1;
}

main() {
a();
b();
print(c);
}
13 changes: 4 additions & 9 deletions Language/Functions/generator_return_type_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +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 It is a static warning if the declared return type of a function
/// marked sync* may not be assigned to Iterable. It is a static warning if
/// the declared return type of a function marked async* may not be assigned
/// to Stream.
///
/// @description Check that it is a compile error, if the declared
/// return type of synchronous generator function may not be assigned
/// to Iterable.
/// @assertion It is a compile-time error if the declared return type of a
/// function marked sync* is not a supertype of Iterable<T> for some type T
///
/// @description Check that it is a compile error, if the declared return type
/// of synchronous generator function is not a supertype of `Iterable<T>`
/// @author a.semenov@unipro.ru

int f() sync* { }
//^
// [analyzer] unspecified
Expand Down
12 changes: 4 additions & 8 deletions Language/Functions/generator_return_type_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
// 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 It is a static warning if the declared return type of a function
/// marked sync* may not be assigned to Iterable. It is a static warning if
/// the declared return type of a function marked async* may not be assigned
/// to Stream.
/// @assertion It is a compile-time error if the declared return type of a
/// function marked sync* or async* is void.
///
/// @description Check that it is a compile error, if the declared
/// return type of synchronous generator function may not be assigned
/// to Iterable but is void.
/// @description Check that it is a compile error, if the declared return type
/// of synchronous generator function is `void`.
/// @issue 32192
/// @author a.semenov@unipro.ru

void h() sync* { }
//^
// [analyzer] unspecified
Expand Down
12 changes: 4 additions & 8 deletions Language/Functions/generator_return_type_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +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 It is a static warning if the declared return type of a function
/// marked sync* may not be assigned to Iterable. It is a static warning if
/// the declared return type of a function marked async* may not be assigned
/// to Stream.
/// @assertion It is a compile-time error if the declared return type of a
/// function marked sync* is not a supertype of Iterable<T> for some type T
///
/// @description Check that it is no compile error, if the declared
/// return type of synchronous generator function may be assigned
/// to Iterable.
/// @description Check that it is no compile error, if the declared return type
/// of synchronous generator function is supertype of `Iterable`.
/// @author a.semenov@unipro.ru

Iterable c() sync* { }

main() {
Expand Down
13 changes: 4 additions & 9 deletions Language/Functions/generator_return_type_t04.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +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 It is a static warning if the declared return type of a function
/// marked sync* may not be assigned to Iterable. It is a static warning if
/// the declared return type of a function marked async* may not be assigned
/// to Stream.
///
/// @description Check that it is no compile error, if the declared
/// return type of synchronous generator function may be assigned
/// to Iterable.
/// @assertion It is a compile-time error if the declared return type of a
/// function marked sync* is not a supertype of Iterable<T> for some type T
///
/// @description Check that it is no compile error, if the declared return type
/// of synchronous generator function is supertype of `Iterable`.
/// @author a.semenov@unipro.ru

dynamic a() sync* { }

Iterable b() sync* { }
Expand Down
12 changes: 4 additions & 8 deletions Language/Functions/generator_return_type_t05.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +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 It is a static warning if the declared return type of a function
/// marked sync* may not be assigned to Iterable. It is a static warning if
/// the declared return type of a function marked async* may not be assigned
/// to Stream.
///
/// @description Check that it is a compile error, if the declared
/// return type of a function marked async* may not be assigned to Stream.
/// @assertion It is a compile-time error if the declared return type of a
/// function marked async* is not a supertype of Stream<T> for some type T
///
/// @description Check that it is a compile error, if the declared return type
/// of a function marked `async*` is not a supertype of Stream<T>
/// @author a.semenov@unipro.ru

int f() async* { }
//^
// [analyzer] unspecified
Expand Down
12 changes: 4 additions & 8 deletions Language/Functions/generator_return_type_t06.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
// 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 It is a static warning if the declared return type of a function
/// marked sync* may not be assigned to Iterable. It is a static warning if
/// the declared return type of a function marked async* may not be assigned
/// to Stream.
/// @assertion It is a compile-time error if the declared return type of a
/// function marked sync* or async* is void.
///
/// @description Check that it is a compile error, if the declared
/// return type of a function marked async* may not be assigned to Stream but is
/// void.
/// @description Check that it is a compile error, if the declared return type
/// of a function marked `async*` is `void`.
/// @issue 32192
/// @author a.semenov@unipro.ru

void h() async* { }
//^
// [analyzer] unspecified
Expand Down
10 changes: 4 additions & 6 deletions Language/Functions/generator_return_type_t07.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
// 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 It is a static warning if the declared return type of a function
/// marked sync* may not be assigned to Iterable. It is a static warning if
/// the declared return type of a function marked async* may not be assigned
/// to Stream.
/// @assertion It is a compile-time error if the declared return type of a
/// function marked async* is not a supertype of Stream<T> for some type T
///
/// @description Check that it is no compile error, if the declared
/// return type of a function marked async* may be assigned to Stream.
/// @description Check that it is no compile error, if the declared return type
/// of a function marked `async*` is a supertype of `Stream<T>`.
/// @author a.semenov@unipro.ru
import 'dart:async';
Expand Down
11 changes: 4 additions & 7 deletions Language/Functions/generator_return_type_t08.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
// 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 It is a static warning if the declared return type of a function
/// marked sync* may not be assigned to Iterable. It is a static warning if
/// the declared return type of a function marked async* may not be assigned
/// to Stream.
///
/// @description Check that it is no compile error, if the declared
/// return type of a function marked async* may be assigned to Stream.
/// @assertion It is a compile-time error if the declared return type of a
/// function marked async* is not a supertype of Stream<T> for some type T
///
/// @description Check that it is no compile error, if the declared return type
/// of a function marked `async*` is a supertype of `Stream<T>`.
/// @author a.semenov@unipro.ru
import 'dart:async';
Expand Down

0 comments on commit ed5f316

Please sign in to comment.