-
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
Rename Local Variable declaration tests. Delete duplicates.
- Loading branch information
Showing
13 changed files
with
495 additions
and
9 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
Language/Statements/Local_Variable_Declaration/declared_type_A01_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,28 @@ | ||
// 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 The declared type of a local variable with a declaration of one | ||
/// of the forms | ||
/// late? T v = e; late? final T v = e; const T v = e; is T | ||
/// | ||
/// @description Checks that the declared type of a local variable with the | ||
/// specified type `T` is `T` | ||
/// @author [email protected] | ||
import '../../../Utils/static_type_helper.dart'; | ||
|
||
main() { | ||
// We use `as dynamic` below to avoid a type promotion on an assignment | ||
late num v1 = 1 as dynamic; | ||
late final num v2 = 2 as dynamic; | ||
num v3 = 3 as dynamic; | ||
final num? v4 = 4 as dynamic; | ||
const num v5 = 5 as dynamic; | ||
|
||
v1.expectStaticType<Exactly<num>>(); | ||
v2.expectStaticType<Exactly<num>>(); | ||
v3.expectStaticType<Exactly<num>>(); | ||
v4.expectStaticType<Exactly<num?>>(); | ||
v5.expectStaticType<Exactly<num>>(); | ||
} |
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
59 changes: 59 additions & 0 deletions
59
Language/Statements/Local_Variable_Declaration/declared_type_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,59 @@ | ||
// 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 The declared type of a local variable with a declaration of one | ||
/// of the forms late? var v = e; late? final v = e; const v = e; is determined | ||
/// as follows: | ||
/// ... | ||
/// • If the static type of e is of the form X & T where X is a type variable, | ||
/// the declared type of v is X. In this case v is immediately promoted to X & T | ||
/// | ||
/// @description Checks that the static type of a variable declared by the | ||
/// statements `late? var v = e; late? final v = e;` is `X` if the static type | ||
/// of `e` is `X & T` where `X` is a type variable. Also test that `v` is | ||
/// promoted to `X & T` | ||
/// @author [email protected] | ||
import '../../../Utils/static_type_helper.dart'; | ||
|
||
test1<T>(T t) { | ||
if (t is int) { | ||
var v = t; | ||
v.isEven; | ||
T x = v; | ||
v = x; | ||
} | ||
} | ||
|
||
test2<T>(T t) { | ||
if (t is int) { | ||
late var v = t; | ||
v.isEven; | ||
T x = v; | ||
v = x; | ||
} | ||
} | ||
|
||
test3<T>(T t) { | ||
if (t is int) { | ||
final v = t; | ||
v.isEven; | ||
T x = v; | ||
} | ||
} | ||
|
||
test4<T>(T t) { | ||
if (t is int) { | ||
late final v = t; | ||
v.isEven; | ||
T x = v; | ||
} | ||
} | ||
|
||
main() { | ||
test1<int>(1); | ||
test2<num>(2); | ||
test3<int>(3); | ||
test4<num>(4); | ||
} |
63 changes: 63 additions & 0 deletions
63
Language/Statements/Local_Variable_Declaration/declared_type_A03_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,63 @@ | ||
// 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 The declared type of a local variable with a declaration of one | ||
/// of the forms late? var v = e; late? final v = e; const v = e; is determined | ||
/// as follows: | ||
/// ... | ||
/// • If the static type of e is of the form X & T where X is a type variable, | ||
/// the declared type of v is X. In this case v is immediately promoted to X & T | ||
/// | ||
/// @description Checks that the static type of a variable declared by the | ||
/// statements `late? var v = e; late? final v = e;` is `X` if the static type | ||
/// of `e` is where `X` is a type variable. Also check that `v` is not | ||
/// erroneously promoted | ||
/// @author [email protected] | ||
test1<T>(T t) { | ||
if (t is int) { | ||
} | ||
var v = t; | ||
v.isEven; | ||
// ^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
test2<T>(T t) { | ||
if (t is int) { | ||
} | ||
late var v = t; | ||
v.isEven; | ||
// ^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
test3<T>(T t) { | ||
if (t is int) { | ||
} | ||
final v = t; | ||
v.isEven; | ||
// ^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
test4<T>(T t) { | ||
if (t is int) { | ||
} | ||
late final v = t; | ||
v.isEven; | ||
// ^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
test1<int>(1); | ||
test2<num>(2); | ||
test3<int>(3); | ||
test4<num>(4); | ||
} |
43 changes: 43 additions & 0 deletions
43
Language/Statements/Local_Variable_Declaration/declared_type_A04_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,43 @@ | ||
// 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 The declared type of a local variable with a declaration of one | ||
/// of the forms late? var v = e; late? final v = e; const v = e; is determined | ||
/// as follows: | ||
/// ... | ||
/// • Otherwise, the declared type of v is the static type of e. | ||
/// | ||
/// @description Checks that static type of a variable declared by the | ||
/// statements `late? var v = e; late? final v = e; const v = e;` is the static | ||
/// type of `e` | ||
/// @author [email protected] | ||
import '../../../Utils/static_type_helper.dart'; | ||
|
||
test<T>(T t) { | ||
if (t is int) { | ||
late final v = t; | ||
v.isEven; | ||
T x = v; | ||
} | ||
} | ||
|
||
main() { | ||
late var v1 = "1"; | ||
v1.expectStaticType<Exactly<String>>(); | ||
|
||
var v2 = 2; | ||
v2.expectStaticType<Exactly<int>>(); | ||
|
||
late final v3 = 3 as num; | ||
v3.expectStaticType<Exactly<num>>(); | ||
|
||
final v4 = 4 as int?; | ||
v4.expectStaticType<Exactly<int?>>(); | ||
|
||
const v5 = 5 as num?; | ||
v5.expectStaticType<Exactly<num?>>(); | ||
|
||
test<int>(42); | ||
} |
30 changes: 30 additions & 0 deletions
30
Language/Statements/Local_Variable_Declaration/declared_type_A04_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,30 @@ | ||
// 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 The declared type of a local variable with a declaration of one | ||
/// of the forms late? var v = e; late? final v = e; const v = e; is determined | ||
/// as follows: | ||
/// ... | ||
/// • Otherwise, the declared type of v is the static type of e. | ||
/// | ||
/// @description Checks that the static type of a variable declared by the | ||
/// statements `late? var v = e; late? final v = e; const v = e;` is the static | ||
/// type of `e`. Check that `v` is not erroneously promoted | ||
/// @author [email protected] | ||
import '../../../Utils/static_type_helper.dart'; | ||
|
||
test<T>(T t) { | ||
if (t is int) { | ||
} | ||
late final v = t; | ||
v.isEven; | ||
// ^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
test<num>(3.14); | ||
} |
41 changes: 41 additions & 0 deletions
41
Language/Statements/Local_Variable_Declaration/late_await_A01_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,41 @@ | ||
// 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 Assume that D is a local variable declaration with the modifier | ||
/// late that declares a variable v, which has an initializing expression e. It | ||
/// is a compile-time error if e contains an await expression a, unless there is | ||
/// a function f which is the immediately enclosing function for a, and f is not | ||
/// the immediately enclosing function for D. | ||
/// | ||
/// @description Checks that it is a compile-time error if initializing | ||
/// expression of a late local variable contains an `await` expression | ||
/// @author [email protected] | ||
import 'dart:async'; | ||
|
||
Future<T> foo<T>(T t) => Future<T>.value(t); | ||
|
||
main() async { | ||
late var v1 = await Future<int>.value(1); | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
late final v2 = await foo<int>(2); | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
late String v3 = await foo<String>("3"); | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
late final int v4 = await Future<int>.value(4); | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
return 0; | ||
} |
Oops, something went wrong.