Skip to content

Commit

Permalink
dart-lang#2956. Add more tests for the type void
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Nov 13, 2024
1 parent 3a07e0e commit b3e7540
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Language/Types/Type_Void/implicit_usage_A01_t01.dart
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 Finally, we need to address situations involving implicit usage
/// of an object whose static type can be `void`. It is a compile-time error for
/// a for-in statement to have an iterator expression of type `T` such that
/// `Iterator<void>` is the most specific instantiation of `Iterator` that is a
/// superinterface of `T`, unless the iteration variable has type `void`.
///
/// @description Checks that it is a compile-time error if in a for-in loop type
/// of the iterator expression is `Iterator<void>` and the type of the iteration
/// variable is not `void`.
/// @author sgrekhov22@gmail.com
/// @issue 57078
void main() {
List<void> list = <void>[1, 2, 3];
for (Object? i in list) {
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
for (dynamic i in list) {
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
for (Null i in list) {
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
}
28 changes: 28 additions & 0 deletions Language/Types/Type_Void/implicit_usage_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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 Finally, we need to address situations involving implicit usage
/// of an object whose static type can be `void`. It is a compile-time error for
/// a for-in statement to have an iterator expression of type `T` such that
/// `Iterator<void>` is the most specific instantiation of `Iterator` that is a
/// superinterface of `T`, unless the iteration variable has type `void`.
///
/// @description Checks that it is not an error if in a for-in loop type of the
/// iterator expression is `Iterator<void>` and the type of the iteration
/// variable is `void`.
/// @author sgrekhov22@gmail.com
import '../../../Utils/expect.dart';

void main() {
List<void> list = <void>[1, 2, 3];
int j = 0;
for (void i in list) {
Expect.equals(++j, i as int);
}
j = 0;
for (var i in list) {
Expect.equals(++j, i as int);
}
}
34 changes: 34 additions & 0 deletions Language/Types/Type_Void/implicit_usage_A02_t01.dart
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 Finally, we need to address situations involving implicit usage
/// of an object whose static type can be `void`. ... It is a compile-time error
/// for an asynchronous for-in statement to have a stream expression of type `T`
/// such that `Stream<void>` is the most specific instantiation of `Stream` that
/// is a superinterface of `T`, unless the iteration variable has type `void`.
///
/// @description Checks that it is a compile-time error if in an asynchronous
/// for-in loop type of the iterator expression is `Stream<void>` and the type
/// of the iteration variable is not `void`.
/// @author sgrekhov22@gmail.com
/// @issue 57078
void main() async {
Stream<void> stream = Stream<void>.fromIterable([1, 2, 3]);
await for (Object? i in stream) {
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
await for (dynamic i in stream) {
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
await for (Null i in stream) {
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
}
28 changes: 28 additions & 0 deletions Language/Types/Type_Void/implicit_usage_A02_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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 Finally, we need to address situations involving implicit usage
/// of an object whose static type can be `void`. ... It is a compile-time error
/// for an asynchronous for-in statement to have a stream expression of type `T`
/// such that `Stream<void>` is the most specific instantiation of `Stream` that
/// is a superinterface of `T`, unless the iteration variable has type `void`.
///
/// @description Checks that it is not an error if in an asynchronous for-in
/// loop type of the iterator expression is `Stream<void>` and the type of the
/// iteration variable is `void`.
/// @author sgrekhov22@gmail.com
import '../../../Utils/expect.dart';

void main() async {
Stream<void> stream = Stream<void>.fromIterable([1, 2, 3]);
int j = 0;
await for (void i in stream) {
Expect.equals(++j, i as int);
}
j = 0;
await for (var i in stream) {
Expect.equals(++j, i as int);
}
}

0 comments on commit b3e7540

Please sign in to comment.