diff --git a/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_A01_t01.dart b/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_A01_t01.dart new file mode 100644 index 0000000000..a19f6da1ec --- /dev/null +++ b/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_A01_t01.dart @@ -0,0 +1,195 @@ +// Copyright (c) 2011, 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 Case ⟨Static or library variable⟩. If `d` declares a static or +/// library variable, the implicitly induced getter of `id` executes as follows: +/// - Non-constant variable with an initializer. In the case where `d` has an +/// initializing expression and is not constant, the implicitly induced getter +/// of `id` is a late-initialized getter. This determines the semantics of an +/// invocation. +/// +/// @description Checks the implicit getter of a static or library variable is +/// late-initialized and evaluated only once. +/// @author msyabro + +import "../../../Utils/expect.dart"; + +String log = ""; + +writeLog(String i) { + log += "$i"; + return i; +} + +var a = writeLog("a"); +String b = writeLog("b"); +final c = writeLog("c"); +final String d = writeLog("d"); + +class C { + static var a = writeLog("a"); + static String b = writeLog("b"); + static final c = writeLog("c"); + static final String d = writeLog("d"); +} + +mixin M { + static var a = writeLog("a"); + static String b = writeLog("b"); + static final c = writeLog("c"); + static final String d = writeLog("d"); +} + +enum E { + e0; + static var a = writeLog("a"); + static String b = writeLog("b"); + static final c = writeLog("c"); + static final String d = writeLog("d"); +} + +class A {} + +extension Ext on A { + static var a = writeLog("a"); + static String b = writeLog("b"); + static final c = writeLog("c"); + static final String d = writeLog("d"); +} + +extension type ET(int _) { + static var a = writeLog("a"); + static String b = writeLog("b"); + static final c = writeLog("c"); + static final String d = writeLog("d"); +} + +main() { + Expect.equals("", log); + + Expect.equals("a", a); + Expect.equals("a", log); + Expect.equals("a", a); + Expect.equals("a", log); + + Expect.equals("b", b); + Expect.equals("ab", log); + Expect.equals("b", b); + Expect.equals("ab", log); + + Expect.equals("c", c); + Expect.equals("abc", log); + Expect.equals("c", c); + Expect.equals("abc", log); + + Expect.equals("d", d); + Expect.equals("abcd", log); + Expect.equals("d", d); + Expect.equals("abcd", log); + + log = ""; + Expect.equals("a", C.a); + Expect.equals("a", log); + Expect.equals("a", C.a); + Expect.equals("a", log); + + Expect.equals("b", C.b); + Expect.equals("ab", log); + Expect.equals("b", C.b); + Expect.equals("ab", log); + + Expect.equals("c", C.c); + Expect.equals("abc", log); + Expect.equals("c", C.c); + Expect.equals("abc", log); + + Expect.equals("d", C.d); + Expect.equals("abcd", log); + Expect.equals("d", C.d); + Expect.equals("abcd", log); + + log = ""; + Expect.equals("a", M.a); + Expect.equals("a", log); + Expect.equals("a", M.a); + Expect.equals("a", log); + + Expect.equals("b", M.b); + Expect.equals("ab", log); + Expect.equals("b", M.b); + Expect.equals("ab", log); + + Expect.equals("c", M.c); + Expect.equals("abc", log); + Expect.equals("c", M.c); + Expect.equals("abc", log); + + Expect.equals("d", M.d); + Expect.equals("abcd", log); + Expect.equals("d", M.d); + Expect.equals("abcd", log); + + log = ""; + Expect.equals("a", E.a); + Expect.equals("a", log); + Expect.equals("a", E.a); + Expect.equals("a", log); + + Expect.equals("b", E.b); + Expect.equals("ab", log); + Expect.equals("b", E.b); + Expect.equals("ab", log); + + Expect.equals("c", E.c); + Expect.equals("abc", log); + Expect.equals("c", E.c); + Expect.equals("abc", log); + + Expect.equals("d", E.d); + Expect.equals("abcd", log); + Expect.equals("d", E.d); + Expect.equals("abcd", log); + + log = ""; + Expect.equals("a", Ext.a); + Expect.equals("a", log); + Expect.equals("a", Ext.a); + Expect.equals("a", log); + + Expect.equals("b", Ext.b); + Expect.equals("ab", log); + Expect.equals("b", Ext.b); + Expect.equals("ab", log); + + Expect.equals("c", Ext.c); + Expect.equals("abc", log); + Expect.equals("c", Ext.c); + Expect.equals("abc", log); + + Expect.equals("d", Ext.d); + Expect.equals("abcd", log); + Expect.equals("d", Ext.d); + Expect.equals("abcd", log); + + log = ""; + Expect.equals("a", ET.a); + Expect.equals("a", log); + Expect.equals("a", ET.a); + Expect.equals("a", log); + + Expect.equals("b", ET.b); + Expect.equals("ab", log); + Expect.equals("b", ET.b); + Expect.equals("ab", log); + + Expect.equals("c", ET.c); + Expect.equals("abc", log); + Expect.equals("c", ET.c); + Expect.equals("abc", log); + + Expect.equals("d", ET.d); + Expect.equals("abcd", log); + Expect.equals("d", ET.d); + Expect.equals("abcd", log); +} diff --git a/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_A01_t02.dart b/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_A01_t02.dart new file mode 100644 index 0000000000..346d92278d --- /dev/null +++ b/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_A01_t02.dart @@ -0,0 +1,78 @@ +// Copyright (c) 2011, 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 Case ⟨Static or library variable⟩. If `d` declares a static or +/// library variable, the implicitly induced getter of `id` executes as follows: +/// - Non-constant variable with an initializer. In the case where `d` has an +/// initializing expression and is not constant, the implicitly induced getter +/// of `id` is a late-initialized getter. This determines the semantics of an +/// invocation. +/// +/// @description Checks that it is not an error if during an evaluation of the +/// initializing expression `id` is invoked. +/// @author msyabro +/// @Issue 42470 +/// @issue 42642 + +import "../../../Utils/expect.dart"; + +int count = 0; + +f(func) { + try { + throw 1; + } on int catch (_) { + count++; + if (count < 5) { + func(); + } + } + count = 0; +} + +int? variable = f(() => variable); +final int? finalVariable = f(() => finalVariable); + +class C { + static int? variable = f(() => variable); + static final int? finalVariable = f(() => finalVariable); +} + +mixin M { + static int? variable = f(() => variable); + static final int? finalVariable = f(() => finalVariable); +} + +enum E { + e0; + static int? variable = f(() => variable); + static final int? finalVariable = f(() => finalVariable); +} + +class A {} + +extension Ext on A { + static int? variable = f(() => variable); + static final int? finalVariable = f(() => finalVariable); +} + +extension type ET(int _) { + static int? variable = f(() => variable); + static final int? finalVariable = f(() => finalVariable); +} + +main() { + Expect.equals(null, variable); + Expect.throws(() { finalVariable; }); + Expect.equals(null, C.variable); + Expect.throws(() { C.finalVariable; }); + Expect.equals(null, M.variable); + Expect.throws(() { M.finalVariable; }); + Expect.equals(null, E.variable); + Expect.throws(() { E.finalVariable; }); + Expect.equals(null, Ext.variable); + Expect.throws(() { Ext.finalVariable; }); + Expect.equals(null, ET.variable); + Expect.throws(() { ET.finalVariable; }); +} diff --git a/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_A01_t03.dart b/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_A01_t03.dart new file mode 100644 index 0000000000..af608a1d57 --- /dev/null +++ b/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_A01_t03.dart @@ -0,0 +1,101 @@ +// Copyright (c) 2021, 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 Case ⟨Static or library variable⟩. If `d` declares a static or +/// library variable, the implicitly induced getter of `id` executes as follows: +/// - Non-constant variable with an initializer. In the case where `d` has an +/// initializing expression and is not constant, the implicitly induced getter +/// of `id` is a late-initialized getter. This determines the semantics of an +/// invocation. +/// +/// @description Checks that it is not an error if during an evaluation of the +/// initializing expression `id` is invoked and the type of the variable is not +/// specified. +/// @author sgrekhov@unipro.ru +/// @issue 46086 + +f(func) {} + +var sVar = f(() => sVar); +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +final sFinal = f(() => sFinal); +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +class C { + static var sVar = f(() => sVar); +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + static final sFinal = f(() => sFinal); +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + static var sVar = f(() => sVar); +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + static final sFinal = f(() => sFinal); +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0; + static var sVar = f(() => sVar); +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + static final sFinal = f(() => sFinal); +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} + +extension Ext on A { + static var sVar = f(() => sVar); +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + static final sFinal = f(() => sFinal); +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(int _) { + static var sVar = f(() => sVar); +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + static final sFinal = f(() => sFinal); +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(sVar); + print(sFinal); + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_A02_t01.dart b/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_A02_t01.dart new file mode 100644 index 0000000000..0cbfe4f028 --- /dev/null +++ b/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_A02_t01.dart @@ -0,0 +1,67 @@ +// Copyright (c) 2011, 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 Case ⟨Static or library variable⟩. If `d` declares a static or +/// library variable, the implicitly induced getter of `id` executes as follows: +/// ... +/// - Constant variable. If `d` declares a constant variable with the +/// initializing expression `e`, the result of executing the implicitly +/// induced getter is the value of the constant expression `e`. +/// +/// @description Checks the result of the implicit getter of a constant static +/// variable. +/// @author msyabro + +import "../../../Utils/expect.dart"; + +class Const { + final x; + const Const(this.x); +} + +const one = const Const(1); +const int two = 2; + +class C { + static const one = const Const(1); + static const int two = 2; +} + +mixin M { + static const one = const Const(1); + static const int two = 2; +} + +enum E { + e0; + static const one = const Const(1); + static const int two = 2; +} + +class A {} + +extension Ext on A { + static const one = const Const(1); + static const int two = 2; +} + +extension type ET(int _) { + static const one = const Const(1); + static const int two = 2; +} + +main() { + Expect.identical(1, one.x); + Expect.identical(2, two); + Expect.identical(1, C.one.x); + Expect.identical(2, C.two); + Expect.identical(1, M.one.x); + Expect.identical(2, M.two); + Expect.identical(1, E.one.x); + Expect.identical(2, E.two); + Expect.identical(1, Ext.one.x); + Expect.identical(2, Ext.two); + Expect.identical(1, ET.one.x); + Expect.identical(2, ET.two); +} diff --git a/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_A02_t02.dart b/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_A02_t02.dart new file mode 100644 index 0000000000..bd152e0ff8 --- /dev/null +++ b/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_A02_t02.dart @@ -0,0 +1,92 @@ +// Copyright (c) 2025, 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 Case ⟨Static or library variable⟩. If `d` declares a static or +/// library variable, the implicitly induced getter of `id` executes as follows: +/// ... +/// - Constant variable. If `d` declares a constant variable with the +/// initializing expression `e`, the result of executing the implicitly +/// induced getter is the value of the constant expression `e`. +/// +/// @description Checks that it is a compile-time error if initializing +/// expression invokes `id`. +/// @author sgrekhov22@gmail.com +/// @issue 59945 + +const int? one = 2 > 1 ? one : null; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified +const int? two = 2 > 1 ? null : two; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + +class C { + static const int? one = 2 > 1 ? one : null; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + static const int? two = 2 > 1 ? null : two; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + static const int? one = 2 > 1 ? one : null; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + static const int? two = 2 > 1 ? null : two; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0; + static const int? one = 2 > 1 ? one : null; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + static const int? two = 2 > 1 ? null : two; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} + +extension Ext on A { + static const int? one = 2 > 1 ? one : null; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + static const int? two = 2 > 1 ? null : two; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(int _) { + static const int? one = 2 > 1 ? one : null; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + static const int? two = 2 > 1 ? null : two; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(one); + print(two); + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_A02_t03.dart b/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_A02_t03.dart new file mode 100644 index 0000000000..7ff45747da --- /dev/null +++ b/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_A02_t03.dart @@ -0,0 +1,92 @@ +// Copyright (c) 2025, 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 Case ⟨Static or library variable⟩. If `d` declares a static or +/// library variable, the implicitly induced getter of `id` executes as follows: +/// ... +/// - Constant variable. If `d` declares a constant variable with the +/// initializing expression `e`, the result of executing the implicitly +/// induced getter is the value of the constant expression `e`. +/// +/// @description Checks that it is a compile-time error if initializing +/// expression invokes `id`. Test the case when the type of the constant is not +/// specified. +/// @author sgrekhov22@gmail.com + +const one = 2 > 1 ? one : null; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified +const two = 2 > 1 ? null : two; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + +class C { + static const one = 2 > 1 ? one : null; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + static const two = 2 > 1 ? null : two; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + static const one = 2 > 1 ? one : null; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + static const two = 2 > 1 ? null : two; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0; + static const one = 2 > 1 ? one : null; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + static const two = 2 > 1 ? null : two; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} + +extension Ext on A { + static const one = 2 > 1 ? one : null; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + static const two = 2 > 1 ? null : two; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(int _) { + static const one = 2 > 1 ? one : null; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + static const two = 2 > 1 ? null : two; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(one); + print(two); + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_t01.dart b/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_t01.dart deleted file mode 100644 index e1b79cb884..0000000000 --- a/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_t01.dart +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) 2011, 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 Let d be the declaration of a variable v. If d is a local or -/// instance variable, then the invocation of the implicit getter of v -/// evaluates to the value stored in v. -/// If d is a static or library variable then the implicit getter method of v -/// executes as follows: -/// - Non-constant variable declaration with initializer. If d is of one of the -/// forms var v = e; , T v = e; , final v = e; , final T v = e; , static -/// v = e; , static T v = e; , static final v = e; or static final T v = e; -/// and no value has yet been stored into v then the initializer expression -/// e is evaluated. If, during the evaluation of e, the getter for v is -/// invoked, a CyclicInitializationError is thrown. If the evaluation -/// succeeded yielding an object o, let r = o, otherwise let r = null. In -/// any case, r is stored into v. The result of executing the getter is r. -/// - Constant variable declaration. If d is of one of the forms const v = e; , -/// const T v = e; , static const v = e; or static const T v = e; the result -/// of the getter is the value of the compile time constant e. Note that a -/// compile time constant cannot depend on itself, so no cyclic references -/// can occur. Otherwise -/// - Variable declaration without initializer. The result of executing the -/// getter method is the value stored in v. -/// @description Checks the result of the getter and that the initializer -/// expression is evaluated only once. -/// @author msyabro - -import "../../../Utils/expect.dart"; - -String log = ""; - -writeLog(int i) { - log = "${log}${i}"; - return i; -} - -class C { - static var a = writeLog(1); - static int b = writeLog(2); - static final c = writeLog(3); - static final int d = writeLog(4); -} - -main() { - Expect.equals(4, C.d); - Expect.equals("4", log, "Lazy static getters execution was wrong!"); - Expect.equals(1, C.a); - Expect.equals("41", log, "Lazy static getters execution was wrong!"); - Expect.equals(2, C.b); - Expect.equals("412", log, "Lazy static getters execution was wrong!"); - Expect.equals(3, C.c); - Expect.equals("4123", log, "Lazy static getters execution was wrong!"); -} diff --git a/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_t02.dart b/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_t02.dart deleted file mode 100644 index ee7550bf18..0000000000 --- a/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_t02.dart +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) 2011, 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 Let d be the declaration of a variable v. If d is a local or -/// instance variable, then the invocation of the implicit getter of v -/// evaluates to the value stored in v. -/// If d is a static or library variable then the implicit getter method of v -/// executes as follows: -/// - Non-constant variable declaration with initializer. If d is of one of the -/// forms var v = e; , T v = e; , final v = e; , final T v = e; , static -/// v = e; , static T v = e; , static final v = e; or static final T v = e; -/// and no value has yet been stored into v then the initializer expression -/// e is evaluated. If, during the evaluation of e, the getter for v is -/// invoked, a CyclicInitializationError is thrown. If the evaluation -/// succeeded yielding an object o, let r = o, otherwise let r = null. In -/// any case, r is stored into v. The result of executing the getter is r. -/// - Constant variable declaration. If d is of one of the forms const v = e; , -/// const T v = e; , static const v = e; or static const T v = e; the result -/// of the getter is the value of the compile time constant e. Note that a -/// compile time constant cannot depend on itself, so no cyclic references -/// can occur. Otherwise -/// - Variable declaration without initializer. The result of executing the -/// getter method is the value stored in v. -/// @note NNBD Spec now reads: If a variable or field is read from during the -/// process of evaluating its own initializer expression, and no write to the -/// variable has occurred, the read is treated as a first read and the -/// nitializer expression is evaluated again. -/// -/// A toplevel or static variable with an initializer is evaluated as if it was -/// marked [late]. Note that this is a change from pre-NNBD semantics in that: -/// -/// Throwing an exception during initializer evaluation no longer sets the -/// variable to [null] -/// -/// Reading the variable during initializer evaluation is no longer checked for, -/// and does not cause an error. -/// -/// @description Checks that if during the evaluation of [e], the getter for [v] -/// is invoked, an error is not thrown. Confirms that [func] gets recursively -/// called by incrementing a counter and stopping the infinite recursion after -/// 20 cycles. This avoids relying on particulars of the behavior on stack -/// overflow and makes the test cheaper to run. -/// @author msyabro -/// @Issue 42470 -/// @issue 42642 - -import "../../../Utils/expect.dart"; - -int count = 0; - -f(func) { - try { - throw 1; // caught exceptions do not matter - } on int catch (_) { - count++; - if (count < 20) func(); - } - count = 0; -} - -class C { - static int? sTyped = f(() => sTyped); - static final int? sFinalTyped = f(() => sFinalTyped); -} - - -main() { - () => C.sTyped; - Expect.equals(null, C.sTyped); - - () => C.sFinalTyped; - Expect.throws(() { C.sFinalTyped; }); -} diff --git a/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_t03.dart b/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_t03.dart deleted file mode 100644 index 9bd7fccf87..0000000000 --- a/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_t03.dart +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2011, 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 Let d be the declaration of a variable v. If d is a local or -/// instance variable, then the invocation of the implicit getter of v -/// evaluates to the value stored in v. -/// If d is a static or library variable then the implicit getter method of v -/// executes as follows: -/// - Non-constant variable declaration with initializer. If d is of one of the -/// forms var v = e; , T v = e; , final v = e; , final T v = e; , static -/// v = e; , static T v = e; , static final v = e; or static final T v = e; -/// and no value has yet been stored into v then the initializer expression -/// e is evaluated. If, during the evaluation of e, the getter for v is -/// invoked, a CyclicInitializationError is thrown. If the evaluation -/// succeeded yielding an object o, let r = o, otherwise let r = null. In -/// any case, r is stored into v. The result of executing the getter is r. -/// - Constant variable declaration. If d is of one of the forms const v = e; , -/// const T v = e; , static const v = e; or static const T v = e; the result -/// of the getter is the value of the compile time constant e. Note that a -/// compile time constant cannot depend on itself, so no cyclic references -/// can occur. Otherwise -/// - Variable declaration without initializer. The result of executing the -/// getter method is the value stored in v. -/// @description Checks that the initializer expression is evaluated at -/// the first use of a static variable. -/// @author msyabro - -import "../../../Utils/expect.dart"; - -var counter = 0; - -class C { - static var sVar = ++counter; - static int sTyped = ++counter; - static final sFinal = ++counter; - static final int sFinalTyped = ++counter; -} - -main() { - Expect.equals(0, counter); - Expect.equals(1, C.sVar); - Expect.equals(1, counter); - Expect.equals(2, C.sTyped); - Expect.equals(2, counter); - Expect.equals(3, C.sFinal); - Expect.equals(3, counter); - Expect.equals(4, C.sFinalTyped); - Expect.equals(4, counter); -} diff --git a/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_t04.dart b/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_t04.dart deleted file mode 100644 index c7c489092b..0000000000 --- a/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_t04.dart +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2011, 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 Let d be the declaration of a variable v. If d is a local or -/// instance variable, then the invocation of the implicit getter of v -/// evaluates to the value stored in v. -/// If d is a static or library variable then the implicit getter method of v -/// executes as follows: -/// - Non-constant variable declaration with initializer. If d is of one of the -/// forms var v = e; , T v = e; , final v = e; , final T v = e; , static -/// v = e; , static T v = e; , static final v = e; or static final T v = e; -/// and no value has yet been stored into v then the initializer expression -/// e is evaluated. If, during the evaluation of e, the getter for v is -/// invoked, a CyclicInitializationError is thrown. If the evaluation -/// succeeded yielding an object o, let r = o, otherwise let r = null. In -/// any case, r is stored into v. The result of executing the getter is r. -/// - Constant variable declaration. If d is of one of the forms const v = e; , -/// const T v = e; , static const v = e; or static const T v = e; the result -/// of the getter is the value of the compile time constant e. Note that a -/// compile time constant cannot depend on itself, so no cyclic references -/// can occur. Otherwise -/// - Variable declaration without initializer. The result of executing the -/// getter method is the value stored in v. -/// @description Checks the result of the getter of a constant static variable. -/// @author msyabro - -import "../../../Utils/expect.dart"; - -class Const { - const Const(this.x); - final x; -} - -class C { - static final sConst = const Const(1); - static final int sConstTyped = 2; -} - -main() { - Expect.equals(1, C.sConst.x); - Expect.equals(2, C.sConstTyped); -} diff --git a/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_t05.dart b/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_t05.dart deleted file mode 100644 index b7f3f17164..0000000000 --- a/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_t05.dart +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2011, 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 Let d be the declaration of a variable v. If d is a local or -/// instance variable, then the invocation of the implicit getter of v -/// evaluates to the value stored in v. -/// If d is a static or library variable then the implicit getter method of v -/// executes as follows: -/// - Non-constant variable declaration with initializer. If d is of one of the -/// forms var v = e; , T v = e; , final v = e; , final T v = e; , static -/// v = e; , static T v = e; , static final v = e; or static final T v = e; -/// and no value has yet been stored into v then the initializer expression -/// e is evaluated. If, during the evaluation of e, the getter for v is -/// invoked, a CyclicInitializationError is thrown. If the evaluation -/// succeeded yielding an object o, let r = o, otherwise let r = null. In -/// any case, r is stored into v. The result of executing the getter is r. -/// - Constant variable declaration. If d is of one of the forms const v = e; , -/// const T v = e; , static const v = e; or static const T v = e; the result -/// of the getter is the value of the compile time constant e. Note that a -/// compile time constant cannot depend on itself, so no cyclic references -/// can occur. Otherwise -/// - Variable declaration without initializer. The result of executing the -/// getter method is the value stored in v. -/// -/// @note NNBD Spec now reads: If a variable or field is read from during the -/// process of evaluating its own initializer expression, and no write to the -/// variable has occurred, the read is treated as a first read and the -/// nitializer expression is evaluated again. -/// -/// A toplevel or static variable with an initializer is evaluated as if it was -/// marked [late]. Note that this is a change from pre-NNBD semantics in that: -/// -/// Reading the variable during initializer evaluation is no longer checked for, -/// and does not cause an error. -/// -/// @description Checks that an error is not thrown when getter is referenced -/// during evaluation of initialization expression. -/// @author kaigorodov -/// @Issue 42470 -/// @issue 42642 - -import "../../../Utils/expect.dart"; - -int count = 0; - -int f() { - return count++ < 20 ? C.sTyped : count; -} - -class C { - static int sTyped = f(); -} - -main() { - Expect.equals (21, C.sTyped); -} diff --git a/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_t06.dart b/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_t06.dart deleted file mode 100644 index ee5d38d6be..0000000000 --- a/Language/Variables/Evaluation_of_Implicit_Variable_Getters/definition_t06.dart +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2021, 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 Let d be the declaration of a variable v. If d is a local or -/// instance variable, then the invocation of the implicit getter of v -/// evaluates to the value stored in v. -/// If d is a static or library variable then the implicit getter method of v -/// executes as follows: -/// - Non-constant variable declaration with initializer. If d is of one of the -/// forms var v = e; , T v = e; , final v = e; , final T v = e; , static -/// v = e; , static T v = e; , static final v = e; or static final T v = e; -/// and no value has yet been stored into v then the initializer expression -/// e is evaluated. If, during the evaluation of e, the getter for v is -/// invoked, a CyclicInitializationError is thrown. If the evaluation -/// succeeded yielding an object o, let r = o, otherwise let r = null. In -/// any case, r is stored into v. The result of executing the getter is r. -/// - Constant variable declaration. If d is of one of the forms const v = e; , -/// const T v = e; , static const v = e; or static const T v = e; the result -/// of the getter is the value of the compile time constant e. Note that a -/// compile time constant cannot depend on itself, so no cyclic references -/// can occur. Otherwise -/// - Variable declaration without initializer. The result of executing the -/// getter method is the value stored in v. -/// -/// @note The language specification says 'If, during the evaluation of [e] -/// (which is the initializing expression for [v]), the getter for [v] is invoked, -/// a [CyclicInitializationError] is thrown', but this is overridden by the -/// following text in the nnbd feature specification: 'If a variable or field is -/// read from during the process of evaluating its own initializer expression, -/// and no write to the variable has occurred, the read is treated as a first -/// read and the initializer expression is evaluated again.' -/// So CyclicInitializationErrors are gone here when null safety is enabled. -/// In the test, [f] returns [null] (typed as [dynamic]), and the evaluation of -/// the initializing expression for [sVar] as well as [sFinal] discards the -/// function literal (() => sVar respectively () => sFinal) without ever -/// executing it. So we do not have a situation where the getter for -/// [sVar]/[sFinal] is invoked during the evaluation of its initializing -/// expression, and both variables just get initialized to the value [null]. No -/// recursion and no errors. -/// -/// @description Checks that an error is not thrown with the null safety turned -/// on. -/// @author sgrekhov@unipro.ru -/// @issue 46086 - -f(func) {} - -class C { - static var sVar = f(() => sVar); -// ^^^^ -// [analyzer] unspecified -// [cfe] unspecified - - static final sFinal = f(() => sFinal); -// ^^^^^^ -// [analyzer] unspecified -// [cfe] unspecified -} - -main() { - C? c; -}