[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: https://github.com/dart-lang/sdk/issues/57038
Change-Id: I71b54dcdad1e6dfd4145badc784ef323bc23417b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413042
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
diff --git a/tests/language/dot_shorthands/dot_shorthand_helper.dart b/tests/language/dot_shorthands/dot_shorthand_helper.dart
index 72a251f..b4ea7d1 100644
--- a/tests/language/dot_shorthands/dot_shorthand_helper.dart
+++ b/tests/language/dot_shorthands/dot_shorthand_helper.dart
@@ -66,15 +66,24 @@
 class ConstructorWithNonFinal {
   final int x;
 
-  ConstructorWithNonFinal field = ConstructorWithNonFinal(1);
+  ConstructorWithNonFinal get field => _constConstructorWithNonFinal;
 
   ConstructorWithNonFinal(this.x);
+  const ConstructorWithNonFinal.constNamed(this.x);
 
   ConstructorWithNonFinal method() => ConstructorWithNonFinal(1);
 
   ConstructorWithNonFinal? methodNullable() => null;
 }
 
+// Prevent infinite recursion with fields.
+const ConstructorWithNonFinal _constConstructorWithNonFinal =
+    _ConstructorWithNonFinalSubclass(1);
+
+class _ConstructorWithNonFinalSubclass extends ConstructorWithNonFinal {
+  const _ConstructorWithNonFinalSubclass(int x) : super.constNamed(x);
+}
+
 class UnnamedConstructor {}
 
 class UnnamedConstructorTypeParameters<T> {}
@@ -101,14 +110,23 @@
   static StaticMember<Integer> property(Integer i) => StaticMember(i);
 
   final T t;
-  StaticMember field = StaticMember.member();
+  StaticMember get field => _constStaticMember;
 
   StaticMember(this.t);
 
+  const StaticMember.constNamed(this.t);
+
   StaticMember method() => StaticMember.member();
   StaticMember? methodNullable() => null;
 }
 
+// Prevent infinite recursion with fields.
+const StaticMember _constStaticMember = _StaticMemberSubclass(1);
+
+class _StaticMemberSubclass<T> extends StaticMember<T> {
+  const _StaticMemberSubclass(T t) : super.constNamed(t);
+}
+
 extension type StaticMemberExt<T>(T x) {
   static StaticMemberExt<int> member() => StaticMemberExt(1);
   static StaticMemberExt<int>? memberNullable() => null;