| // 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 The declaring parameter list of the primary constructor |
| /// introduces a new scope, the primary initializer scope, whose enclosing scope |
| /// is the body scope of D. Each of the parameters in said parameter list is |
| /// introduced into this scope. |
| /// |
| /// The same parameter list also introduces the primary parameter scope, whose |
| /// enclosing scope is also the body scope of the class. Every primary parameter |
| /// which is not declaring, not initializing, and not a super parameter is |
| /// introduced into this scope. |
| /// |
| /// The primary initializer scope is the current scope for the initializing |
| /// expression, if any, of each non-late instance variable declaration. It is |
| /// also the current scope for the initializer list in the body part of the |
| /// primary constructor, if any. |
| /// |
| /// The primary parameter scope is the current scope for the body of the body |
| /// part of the primary constructor, if any. |
| /// |
| /// @description Check that the primary initializer scope is not the current |
| /// scope for the initializing expression of a static variable declaration. |
| /// @author sgrekhov22@gmail.com |
| |
| // SharedOptions=--enable-experiment=primary-constructors |
| |
| String x = "top level"; |
| |
| class C1(var String x) { |
| String instance = x; |
| static String staticVariable = x; |
| // ^ |
| // [analyzer] unspecified |
| // [cfe] unspecified |
| } |
| |
| class C2([final String x = "default"]) { |
| String instance = x; |
| static String staticVariable = x; |
| // ^ |
| // [analyzer] unspecified |
| // [cfe] unspecified |
| } |
| |
| class C3({var String x = "default"}) { |
| String instance = x; |
| static String staticVariable = x; |
| // ^ |
| // [analyzer] unspecified |
| // [cfe] unspecified |
| } |
| |
| class C4({required final String x}) { |
| String instance = x; |
| static String staticVariable = x; |
| // ^ |
| // [analyzer] unspecified |
| // [cfe] unspecified |
| } |
| |
| extension type ET1(String x) { |
| static String staticVariable = x; |
| // ^ |
| // [analyzer] unspecified |
| // [cfe] unspecified |
| } |
| |
| extension type ET2([String x = "default"]) { |
| static String staticVariable = x; |
| // ^ |
| // [analyzer] unspecified |
| // [cfe] unspecified |
| } |
| |
| extension type ET3({final String x = "default"}) { |
| static String staticVariable = x; |
| // ^ |
| // [analyzer] unspecified |
| // [cfe] unspecified |
| } |
| |
| extension type ET4({required String x}) { |
| static String staticVariable = x; |
| // ^ |
| // [analyzer] unspecified |
| // [cfe] unspecified |
| } |
| |
| enum const E1(final String x) { |
| e0("E1"); |
| static String staticVariable = x; |
| // ^ |
| // [analyzer] unspecified |
| // [cfe] unspecified |
| } |
| |
| enum const E2([final String x = "default"]) { |
| e0("E2"); |
| static String staticVariable = x; |
| // ^ |
| // [analyzer] unspecified |
| // [cfe] unspecified |
| } |
| |
| enum const E3({final String x = "default"}) { |
| e0(x: "E3"); |
| static String staticVariable = x; |
| // ^ |
| // [analyzer] unspecified |
| // [cfe] unspecified |
| } |
| |
| enum const E4({required final String x}) { |
| e0(x: "E4"); |
| static String staticVariable = x; |
| // ^ |
| // [analyzer] unspecified |
| // [cfe] unspecified |
| } |
| |
| main() { |
| print(C1); |
| print(C2); |
| print(C3); |
| print(C4); |
| print(ET1); |
| print(ET2); |
| print(ET3); |
| print(ET4); |
| print(E1); |
| print(E2); |
| print(E3); |
| print(E4); |
| } |