Skip to content

Commit

Permalink
dart-lang#2145. Update existing "Evaluation of Implicit Variable Gett…
Browse files Browse the repository at this point in the history
…ers" tests
  • Loading branch information
sgrekhov committed Jan 21, 2025
1 parent 1a53098 commit 9685814
Show file tree
Hide file tree
Showing 12 changed files with 625 additions and 341 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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; });
}
Original file line number Diff line number Diff line change
@@ -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 [email protected]
/// @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);
}
Loading

0 comments on commit 9685814

Please sign in to comment.