diff --git a/Language/Classes/Instance_Variables/constant_t01.dart b/Language/Classes/Instance_Variables/constant_t01.dart index 81ce1c4b39..0628a52306 100644 --- a/Language/Classes/Instance_Variables/constant_t01.dart +++ b/Language/Classes/Instance_Variables/constant_t01.dart @@ -11,11 +11,21 @@ class C { const v1 = 1; -//^ +//^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + const var v2 = 2; +//^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + const int v3 = 3; +//^^^^^ // [analyzer] unspecified // [cfe] unspecified } main() { - new C().v1; + print(C); } diff --git a/Language/Variables/covariant_t01.dart b/Language/Variables/covariant_t01.dart new file mode 100644 index 0000000000..2d9a9223ec --- /dev/null +++ b/Language/Variables/covariant_t01.dart @@ -0,0 +1,44 @@ +// 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 It is a compile-time error for the declaration of a variable +/// which is not an instance variable to include the modifier covariant. +/// +/// @description Checks that a compile-time error if not-instance variable has a +/// modifier `covariant` +/// @author sgrekhov22@gmail.com + + covariant var c1 = 1; +//^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + covariant int c2 = 2; +//^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +class C { + static covariant var c3 = 3; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + static covariant int c4 = 4; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + covariant var c5 = 5; +//^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + covariant int c6 = 6; +//^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} diff --git a/Language/Variables/multiple_t01.dart b/Language/Variables/multiple_t01.dart new file mode 100644 index 0000000000..5c5d27e07d --- /dev/null +++ b/Language/Variables/multiple_t01.dart @@ -0,0 +1,75 @@ +// 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 An ⟨initializedVariableDeclaration⟩ that declares two or more +/// variables is equivalent to multiple variable declarations declaring the same +/// set of variable names, in the same order, with the same initialization, +/// type, and modifiers +/// +/// @description Checks that two or more variables is equivalent to multiple +/// variable declarations declaring the same set of variable names, in the same +/// order, with the same initialization, type, and modifiers +/// @author sgrekhov22@gmail.com + +import "../../Utils/expect.dart"; + +var v1 = 1, v2, v3 = "3"; +int? i1 = 1, i2, i3 = i1; +final int fi1 = 1, fi2 = fi1, fi3 = fi2; + +class C { + static var s1 = 1, s2, s3 = "3"; + static int? si1 = 1, si2, si3 = si1; + static final int sfi1 = 1, sfi2 = sfi1, sfi3 = sfi2; + + var _v1 = 1, _v2, _v3 = "3"; + int? _i1 = 1, _i2, _i3 = 3; + final int _fi1 = 1, _fi2 = 2; +} + +main() { + var lv1 = 1, lv2, lv3 = "3"; + int? li1 = 1, li2, li3 = li1; + final int lfi1 = 1, lfi2 = lfi1, lfi3 = lfi2; + + Expect.equals(1, v1); + Expect.isNull(v2); + Expect.equals("3", v3); + Expect.equals(1, i1); + Expect.isNull(i2); + Expect.equals(1, i3); + Expect.equals(1, fi1); + Expect.equals(1, fi1); + Expect.equals(1, fi3); + + Expect.equals(1, C.s1); + Expect.isNull(C.s2); + Expect.equals("3", C.s3); + Expect.equals(1, C.si1); + Expect.isNull(C.si2); + Expect.equals(1, C.si3); + Expect.equals(1, C.sfi1); + Expect.equals(1, C.sfi1); + Expect.equals(1, C.sfi3); + + C c = C(); + Expect.equals(1, c._v1); + Expect.isNull(c._v2); + Expect.equals("3", c._v3); + Expect.equals(1, c._i1); + Expect.isNull(c._i2); + Expect.equals(3, c._i3); + Expect.equals(1, c._fi1); + Expect.equals(1, c._fi1); + + Expect.equals(1, lv1); + Expect.isNull(lv2); + Expect.equals("3", lv3); + Expect.equals(1, li1); + Expect.isNull(li2); + Expect.equals(1, li3); + Expect.equals(1, lfi1); + Expect.equals(1, lfi1); + Expect.equals(1, lfi3); +} diff --git a/Language/Variables/multiple_t02.dart b/Language/Variables/multiple_t02.dart new file mode 100644 index 0000000000..d66f4db036 --- /dev/null +++ b/Language/Variables/multiple_t02.dart @@ -0,0 +1,77 @@ +// 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 An ⟨initializedVariableDeclaration⟩ that declares two or more +/// variables is equivalent to multiple variable declarations declaring the same +/// set of variable names, in the same order, with the same initialization, +/// type, and modifiers +/// +/// @description Checks that two or more variables is equivalent to multiple +/// variable declarations declaring the same set of variable names, in the same +/// order, with the same initialization, type, and modifiers. Test late +/// variables. +/// @author sgrekhov22@gmail.com + +import "../../Utils/expect.dart"; + +class Log { + static String log = ""; + static void clearLog() { + log = ""; + } + + int val; + Log(this.val) { + log += "$val;"; + } +} + +late var v1 = Log(1), v2 = Log(2); +late final Log v3 = Log(3), v4 = v3; + +class C { + static late var v5 = Log(5), v6 = Log(6); + static late final Log v7 = Log(7), v8 = v7; + + late var v9 = Log(9), v10 = Log(10); + late final Log v11 = Log(11), v12 = v11; +} + +main() { + late var v13 = Log(13), v14 = Log(14); + late final Log v15 = Log(15), v16 = v15; + + Expect.equals("", Log.log); + print(v1); + Expect.equals("1;", Log.log); + print(v2); + Expect.equals("1;2;", Log.log); + print(v4); + Expect.equals("1;2;3;", Log.log); + + Log.clearLog(); + print(C.v5); + Expect.equals("5;", Log.log); + print(C.v6); + Expect.equals("5;6;", Log.log); + print(C.v8); + Expect.equals("5;6;7;", Log.log); + + Log.clearLog(); + C c = C(); + print(c.v9); + Expect.equals("9;", Log.log); + print(c.v10); + Expect.equals("9;10;", Log.log); + print(c.v12); + Expect.equals("9;10;11;", Log.log); + + Log.clearLog(); + print(v13); + Expect.equals("13;", Log.log); + print(v14); + Expect.equals("13;14;", Log.log); + print(v16); + Expect.equals("13;14;15;", Log.log); +} diff --git a/Language/Variables/multiple_t03.dart b/Language/Variables/multiple_t03.dart new file mode 100644 index 0000000000..0dbeabb173 --- /dev/null +++ b/Language/Variables/multiple_t03.dart @@ -0,0 +1,35 @@ +// 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 An ⟨initializedVariableDeclaration⟩ that declares two or more +/// variables is equivalent to multiple variable declarations declaring the same +/// set of variable names, in the same order, with the same initialization, +/// type, and modifiers +/// +/// @description Checks that it is a compile-time error to use an instance +/// variable in an initializing expression of the another instance variable +/// @author sgrekhov22@gmail.com + +class C { + var v1 = 1, v2 = v1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + + final int v3 = 3, v4 = v3; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + + late final int v5 = 5, v6 = v5, v7 = v3; // No error for the late variables + + int v8 = v5; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(C); +} diff --git a/Language/Variables/static_variable_t01.dart b/Language/Variables/static_variable_t01.dart index 96da8b9e47..e85d84f28f 100644 --- a/Language/Variables/static_variable_t01.dart +++ b/Language/Variables/static_variable_t01.dart @@ -2,13 +2,10 @@ // 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 static variable is a variable that is not associated with -/// a particular instance, but rather with an entire library or class. Static -/// variables include library variables and class variables. Class variables -/// are variables whose declaration is immediately nested inside a class -/// declaration and includes the modifer static. -/// A library variable is implicitly static. It is a compile-time error to -/// preface a top-level variable declaration with the built-in identier static. +/// @assertion A static variable is a variable whose declaration is immediately +/// nested inside a class, mixin, enum, or extension declaration and includes +/// the modifier static +/// /// @description Checks that a static variable is not associated with a /// particular instance. /// @author kaigorodov diff --git a/Language/Variables/static_variable_t02.dart b/Language/Variables/static_variable_t02.dart index 1f2830866a..9c8a9f60f5 100644 --- a/Language/Variables/static_variable_t02.dart +++ b/Language/Variables/static_variable_t02.dart @@ -2,20 +2,30 @@ // 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 static variable is a variable that is not associated with -/// a particular instance, but rather with an entire library or class. Static -/// variables include library variables and class variables. Class variables -/// are variables whose declaration is immediately nested inside a class -/// declaration and includes the modifer static. -/// A library variable is implicitly static. It is a compile-time error to -/// preface a top-level variable declaration with the built-in identier static. +/// @assertion It is a compile-time error if a library variable declaration has +/// the modifier static. +/// /// @description Checks that it is a compile-time error to preface a top-level -/// variable declaration with the built-in identifier static. +/// variable declaration with the built-in identifier `static`. /// @author kaigorodov + static var v1 = 1; +//^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + static int v2 = 1; +//^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + static final v3 = 1; +//^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified -static var foo = 1; -//^ + late static final v4 = 1; +// ^^^^^^ // [analyzer] unspecified // [cfe] unspecified