forked from dart-lang/co19
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dart-lang#2956. Add more type
void
tests
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
Language/Functions/Type_of_a_Function/return_type_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,46 @@ | ||
// 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 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 setter or operator `[]=` declaration does not | ||
/// declare a return type then the return type is `void` and it's a compile-time | ||
/// error to return a value from this declaration. | ||
/// @author sgrekhov22@gmail.com | ||
set globalSetter(int _) { | ||
return 0; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
class C { | ||
operator []=(int index, Object? value) { | ||
return 0; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
static set staticSetter(int _) { | ||
return 0; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
set instanceSetter(int _) { | ||
return 0; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} | ||
|
||
main() { | ||
globalSetter = 1; | ||
print(C); | ||
} |
34 changes: 34 additions & 0 deletions
34
Language/Functions/function_body_short_syntax_A03_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,34 @@ | ||
// 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 `FutureOr<void>`. | ||
/// @author sgrekhov22@qmail.com | ||
import 'dart:async'; | ||
|
||
FutureOr<void> f1() => 1; | ||
FutureOr<void> f2() => null; | ||
FutureOr<void> f3<T>(T t) => t; | ||
|
||
FutureOr<void> f4() { | ||
return 1; | ||
} | ||
|
||
main() { | ||
print(f1); | ||
print(f2); | ||
print(f3); | ||
print(f4); | ||
} |