Skip to content

Commit

Permalink
dart-lang#2145. Update assertions and descriptions in the current Loc…
Browse files Browse the repository at this point in the history
…al variable declaration tests
  • Loading branch information
sgrekhov committed Aug 29, 2023
1 parent e4521ee commit 821d318
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 variable declaration statement of the form var v; is equivalent
/// to var v = null;. A variable declaration statement of the form T v; is
/// equivalent to T v = null;.
/// @description Checks that a variable declaration statements of the form var id;
/// and T id; are equivalent to a variable declaration of the form T id = null,
/// regardless of the type T.
/// @assertion A local variable declaration of the form var v; is equivalent to
/// var v = null;. If T is a nullable type then a local variable declaration of
/// the form T v; is equivalent to T v = null;
///
/// @description Checks that a variable declaration statements of the form
/// `var id;` and `T id;` are equivalent to a variable declaration of the form
/// `T id = null` if `T` is `var` or refers to a nullable type.
/// @author vasya
import '../../../Utils/expect.dart';
Expand Down Expand Up @@ -50,4 +51,3 @@ main() {
f? id8;
Expect.equals(null, id8);
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
// 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 Executing a variable declaration statement of one of the forms
/// var v = e;, T v = e;, const v = e;, const T v = e;, final v = e; or
/// @assertion Execution of a variable declaration statement of one of the forms
/// var v = e; T v = e; const v = e; const T v = e; final v = e; or
/// final T v = e; proceeds as follows:
/// The expression e is evaluated to an object o. Then, the variable v is set
/// to o.
/// @description Checks that a variable declaration statement T id = e; indeed
/// results in variable id being assigned the value of e, whether or not it's
/// final.
/// The expression e is evaluated to an object o. A dynamic type error occurs if
/// the dynamic type of o is not a subtype of the actual declared type of v.
/// Otherwise, the variable v is bound to o.
///
/// @description Checks that a variable declaration statement `T id = e;` indeed
/// results in a variable `id` being assigned the value of `e`, whether or not
/// it's final.
/// @author vasya
/// @reviewer rodionov
import '../../../Utils/expect.dart';

Expand All @@ -34,4 +35,3 @@ main() {
v = null;
Expect.isTrue(id3 == v);
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// 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 Executing a variable declaration statement of one of the forms
/// var v = e;, T v = e;, const v = e;, const T v = e;, final v = e; or
/// @assertion Execution of a variable declaration statement of one of the forms
/// var v = e; T v = e; const v = e; const T v = e; final v = e; or
/// final T v = e; proceeds as follows:
/// The expression e is evaluated to an object o. Then, the variable v is set
/// to o.
/// @description Checks that an expression e is evaluated correctly in a multiple
/// variable declaration statement.
/// The expression e is evaluated to an object o. A dynamic type error occurs if
/// the dynamic type of o is not a subtype of the actual declared type of v.
/// Otherwise, the variable v is bound to o.
///
/// @description Checks that an expression e is evaluated correctly in a
/// multiple variable declaration statement.
/// @author msyabro
import '../../../Utils/expect.dart';
Expand Down
13 changes: 6 additions & 7 deletions Language/Statements/Local_Variable_Declaration/syntax_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +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 A variable declaration statement declares a new local variable.
/// localVariableDeclaration:
/// initializedVariableDeclaration;’
/// ;
/// @description Checks several assignments of variables declared as "T id;"
/// that are correct and do not produce static warnings.
/// @assertion A variable declaration statement, also known as a local variable
/// declaration, has the following form:
/// ⟨localVariableDeclaration⟩ ::= ⟨metadata⟩⟨initializedVariableDeclaration⟩‘;’
///
/// @description Checks several assignments of variables declared as `T id;`
/// that are correct and do not produce errors or warnings.
/// @author vasya

class S {}
class T extends S {}
class C extends T {}
Expand Down
15 changes: 6 additions & 9 deletions Language/Statements/Local_Variable_Declaration/syntax_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +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 variable declaration statement declares a new local variable.
/// localVariableDeclaration:
/// initializedVariableDeclaration;’
/// ;
/// @description Checks several assignments of variables declared as "T id = e;"
/// that are correct and do not produce static warnings.
/// @assertion A variable declaration statement, also known as a local variable
/// declaration, has the following form:
/// ⟨localVariableDeclaration⟩ ::= ⟨metadata⟩⟨initializedVariableDeclaration⟩‘;’
///
/// @description Checks several assignments of variables declared as `T id = e;`
/// that are correct and do not produce errors or warnings.
/// @author vasya
/// @reviewer rodionov
/// @reviewer iefremov
class T {}
class S extends T {}
Expand Down
13 changes: 6 additions & 7 deletions Language/Statements/Local_Variable_Declaration/syntax_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +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 A variable declaration statement declares a new local variable.
/// localVariableDeclaration:
/// initializedVariableDeclaration;’
/// ;
/// @description Checks that a variable declaration statement T id; must end
/// with a semicolon.
/// @assertion A variable declaration statement, also known as a local variable
/// declaration, has the following form:
/// ⟨localVariableDeclaration⟩ ::= ⟨metadata⟩⟨initializedVariableDeclaration⟩‘;’
///
/// @description Checks that a variable declaration statement `T id;` have a
/// semicolon at the end.
/// @author vasya

class T {}

main() {
Expand Down
13 changes: 6 additions & 7 deletions Language/Statements/Local_Variable_Declaration/syntax_t04.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +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 A variable declaration statement declares a new local variable.
/// localVariableDeclaration:
/// initializedVariableDeclaration;’
/// ;
/// @description Checks that a variable declaration statement T id = e; must end
/// with a semicolon.
/// @assertion A variable declaration statement, also known as a local variable
/// declaration, has the following form:
/// ⟨localVariableDeclaration⟩ ::= ⟨metadata⟩⟨initializedVariableDeclaration⟩‘;’
///
/// @description Checks that a variable declaration statement `T id = e;` must
/// end with a semicolon.
/// @author vasya

class T {}

main() {
Expand Down
15 changes: 9 additions & 6 deletions Language/Statements/Local_Variable_Declaration/syntax_t05.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
// 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 variable declaration statement declares a new local variable.
/// localVariableDeclaration:
/// initializedVariableDeclaration ’;’
/// ;
/// @description Checks that the variable 'int id;' declared in a block is not
/// available in a scope that encloses this block.
/// @assertion A variable declaration statement, also known as a local variable
/// declaration, has the following form:
/// ⟨localVariableDeclaration⟩ ::= ⟨metadata⟩⟨initializedVariableDeclaration⟩‘;’
///
/// Each local variable declaration introduces a local variable into the current
/// scope.
///
/// @description Checks that the variable `int id;` declared in a block is not
/// available outside of this block.
/// @author rodionov
main() {
Expand Down
14 changes: 8 additions & 6 deletions Language/Statements/Local_Variable_Declaration/syntax_t06.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
// 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 variable declaration statement declares a new local variable.
/// localVariableDeclaration:
/// initializedVariableDeclaration ’;’
/// ;
/// @description Checks that the variable declared 'int id;' in a block is not
/// @assertion A variable declaration statement, also known as a local variable
/// declaration, has the following form:
/// ⟨localVariableDeclaration⟩ ::= ⟨metadata⟩⟨initializedVariableDeclaration⟩‘;’
///
/// Each local variable declaration introduces a local variable into the current
/// scope.
///
/// @description Checks that the variable declared `int id;` in a block is not
/// available in another block that isn't included in the first one.
/// @author rodionov
/// @reviewer iefremov
main() {
{
Expand Down
13 changes: 7 additions & 6 deletions Language/Statements/Local_Variable_Declaration/syntax_t07.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
// 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 variable declaration statement declares a new local variable.
/// localVariableDeclaration:
/// initializedVariableDeclaration ’;’
/// ;
/// @assertion A variable declaration statement, also known as a local variable
/// declaration, has the following form:
/// ⟨localVariableDeclaration⟩ ::= ⟨metadata⟩⟨initializedVariableDeclaration⟩‘;’
///
/// Each local variable declaration introduces a local variable into the current
/// scope.
///
/// @description Checks that a declared local variable is also available in the
/// nested scopes.
/// @author rodionov
/// @reviewer iefremov
main() {
int id;
Expand Down
12 changes: 7 additions & 5 deletions Language/Statements/Local_Variable_Declaration/syntax_t08.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
// 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 variable declaration statement declares a new local variable.
/// localVariableDeclaration:
/// initializedVariableDeclaration ’;’
/// ;
/// @assertion A variable declaration statement, also known as a local variable
/// declaration, has the following form:
/// ⟨localVariableDeclaration⟩ ::= ⟨metadata⟩⟨initializedVariableDeclaration⟩‘;’
///
/// Each local variable declaration introduces a local variable into the current
/// scope.
///
/// @description Checks that a newly introduced variable may shadow the one
/// declared in an enclosing scope but doesn't replace it.
/// @author rodionov
/// @reviewer iefremov
import '../../../Utils/expect.dart';

Expand Down
10 changes: 5 additions & 5 deletions Language/Statements/Local_Variable_Declaration/syntax_t11.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
// 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 variable declaration statement declares a new local variable.
/// localVariableDeclaration:
/// initializedVariableDeclaration ’;’
/// ;
/// @assertion It is a compile-time error if a local variable is referenced at a
/// source code location that is before the end of its initializing expression,
/// if any, and otherwise before the declaring occurrence of the identifier
/// which names the variable.
///
/// @description Checks that a variable is introduced into the scope after a
/// variable declaration statement is evaluated, and the name of this variable
/// cannot be used in its initialization.
/// @author iefremov

main() {
var x;
Function f = () {x = f;};
Expand Down
10 changes: 4 additions & 6 deletions Language/Statements/Local_Variable_Declaration/syntax_t12.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
// 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 variable declaration statement declares a new local variable.
/// localVariableDeclaration:
/// initializedVariableDeclaration;’
/// ;
/// @assertion A variable declaration statement, also known as a local variable
/// declaration, has the following form:
/// ⟨localVariableDeclaration⟩ ::= ⟨metadata⟩⟨initializedVariableDeclaration⟩‘;’
///
/// @description Checks that the type T in a variable declaration can be
/// parameterized.
/// @author kaigorodov

class T<K,V> {}

main() {
T<int, String> id;
}

14 changes: 6 additions & 8 deletions Language/Statements/Local_Variable_Declaration/syntax_t13.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +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 A variable declaration statement declares a new local variable.
/// localVariableDeclaration:
/// initializedVariableDeclaration;’
/// ;
/// @description Checks that incorrect syntax of type parameters causes compile
/// error.
/// @assertion A variable declaration statement, also known as a local variable
/// declaration, has the following form:
/// ⟨localVariableDeclaration⟩ ::= ⟨metadata⟩⟨initializedVariableDeclaration⟩‘;’
///
/// @description Checks that incorrect syntax of type parameters causes a
/// compile-time error.
/// @author kaigorodov

class T<K,V> {}

main() {
Expand All @@ -19,4 +18,3 @@ main() {
// [analyzer] unspecified
// [cfe] unspecified
}

19 changes: 11 additions & 8 deletions Language/Statements/Local_Variable_Declaration/syntax_t14.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +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 A variable declaration statement declares a new local variable.
/// localVariableDeclaration:
/// initializedVariableDeclaration ’;’
/// ;
/// @description Checks that a variable declaration statement var id; introduces
/// a new variable id with dynamic static type into the innermost enclosing scope.
/// @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 Null then the declared type of v is dynamic.
///
/// @description Checks that a variable declaration statement `var id;`
/// introduces a new variable `id` with `dynamic` static type into the innermost
/// enclosing scope.
/// @author vasya
import '../../../Utils/expect.dart';
Expand All @@ -16,8 +18,9 @@ class C {}

main() {
var id;
Expect.isTrue(id is dynamic);
Expect.runtimeIsType<dynamic>(id);
Expect.throws(() {
id.whatever;
});
id = false;
id = "";
id = 2;
Expand Down
18 changes: 10 additions & 8 deletions Language/Statements/Local_Variable_Declaration/syntax_t15.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 variable declaration statement declares a new local variable.
/// localVariableDeclaration:
/// initializedVariableDeclaration ’;’
/// ;
/// @description Checks that a variable declaration statement var id = e;
/// introduces a new variable id with dynamic static type into the innermost
/// @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 Null then the declared type of v is dynamic.
///
/// @description Checks that a variable declaration statement `var id = null;`
/// introduces a new variable `id` with `dynamic` static type into the innermost
/// enclosing scope.
/// @author vasya
Expand All @@ -17,8 +18,9 @@ class C {}

main() {
var id = null;
Expect.isTrue(id is dynamic);
Expect.runtimeIsType<dynamic>(id);
Expect.throws(() {
id.whatever;
});
id = false;
id = "";
id = 2;
Expand Down

0 comments on commit 821d318

Please sign in to comment.