diff --git a/tests/language/wildcard_variables/import/import_error_test.dart b/tests/language/wildcard_variables/import/import_error_test.dart new file mode 100644 index 00000000000..65f8e68433a --- /dev/null +++ b/tests/language/wildcard_variables/import/import_error_test.dart @@ -0,0 +1,35 @@ +// Copyright (c) 2024, 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. + +// `_` import prefixes are non-binding. This tests that we can't access the +// top-level declarations of that imported library. + +// SharedOptions=--enable-experiment=wildcard-variables + +import 'import_lib.dart' as _; + +main() { + var value = 'str'; + + _.topLevel; +//^ +// [analyzer] unspecified +// [cfe] unspecified + + _.C(value); +//^ +// [analyzer] unspecified +// [cfe] unspecified + + // Private extensions can't be used. + value.bar; +//^ +// [analyzer] unspecified +// [cfe] unspecified + + value.fn; +//^ +// [analyzer] unspecified +// [cfe] unspecified +} diff --git a/tests/language/wildcard_variables/import/import_lib.dart b/tests/language/wildcard_variables/import/import_lib.dart new file mode 100644 index 00000000000..2fcf60b1a8e --- /dev/null +++ b/tests/language/wildcard_variables/import/import_lib.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2024, 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. + +// SharedOptions=--enable-experiment=wildcard-variables + +int topLevel = 1; + +class C { + final bool bar; + final bool fn; + + C(String str) + : bar = str.bar, + fn = str.fn; +} + +extension StringExtension on String { + bool get foo => true; +} + +extension _PrivateStringExtension on String { + bool get bar => true; +} + +extension on String { + bool get fn => true; +} diff --git a/tests/language/wildcard_variables/import/import_test.dart b/tests/language/wildcard_variables/import/import_test.dart new file mode 100644 index 00000000000..7b5d76d34b8 --- /dev/null +++ b/tests/language/wildcard_variables/import/import_test.dart @@ -0,0 +1,17 @@ +// Copyright (c) 2024, 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. + +// Import prefixes named `_` are non-binding, but will provide access to the +// non-private extensions in that library. + +// SharedOptions=--enable-experiment=wildcard-variables + +import 'package:expect/expect.dart'; + +import 'import_lib.dart' as _; + +main() { + var value = 'str'; + Expect.isTrue(value.foo); +}