Skip to content

Commit 43a0777

Browse files
kallentuCommit Queue
authored andcommitted
[tests] Fix infinite loop in dot shorthands test.
Every time we called the static method `member()` in `StaticMember` it would initialize `field` which calls `member()` again. This CL fixes that infinite loop in the tests. Bug: #57038 Change-Id: I71b54dcdad1e6dfd4145badc784ef323bc23417b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413042 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Kallen Tu <[email protected]>
1 parent 25a8f54 commit 43a0777

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

tests/language/dot_shorthands/dot_shorthand_helper.dart

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,24 @@ class ConstructorClass {
6666
class ConstructorWithNonFinal {
6767
final int x;
6868

69-
ConstructorWithNonFinal field = ConstructorWithNonFinal(1);
69+
ConstructorWithNonFinal get field => _constConstructorWithNonFinal;
7070

7171
ConstructorWithNonFinal(this.x);
72+
const ConstructorWithNonFinal.constNamed(this.x);
7273

7374
ConstructorWithNonFinal method() => ConstructorWithNonFinal(1);
7475

7576
ConstructorWithNonFinal? methodNullable() => null;
7677
}
7778

79+
// Prevent infinite recursion with fields.
80+
const ConstructorWithNonFinal _constConstructorWithNonFinal =
81+
_ConstructorWithNonFinalSubclass(1);
82+
83+
class _ConstructorWithNonFinalSubclass extends ConstructorWithNonFinal {
84+
const _ConstructorWithNonFinalSubclass(int x) : super.constNamed(x);
85+
}
86+
7887
class UnnamedConstructor {}
7988

8089
class UnnamedConstructorTypeParameters<T> {}
@@ -101,14 +110,23 @@ class StaticMember<T> {
101110
static StaticMember<Integer> property(Integer i) => StaticMember(i);
102111

103112
final T t;
104-
StaticMember field = StaticMember.member();
113+
StaticMember get field => _constStaticMember;
105114

106115
StaticMember(this.t);
107116

117+
const StaticMember.constNamed(this.t);
118+
108119
StaticMember method() => StaticMember.member();
109120
StaticMember? methodNullable() => null;
110121
}
111122

123+
// Prevent infinite recursion with fields.
124+
const StaticMember _constStaticMember = _StaticMemberSubclass(1);
125+
126+
class _StaticMemberSubclass<T> extends StaticMember<T> {
127+
const _StaticMemberSubclass(T t) : super.constNamed(t);
128+
}
129+
112130
extension type StaticMemberExt<T>(T x) {
113131
static StaticMemberExt<int> member() => StaticMemberExt(1);
114132
static StaticMemberExt<int>? memberNullable() => null;

0 commit comments

Comments
 (0)