[wildcard-variables] Add wildcard import prefix tests.

Bug: https://github.com/dart-lang/sdk/issues/55652
Change-Id: I9f17727bcc96bec9fbb01664244a44710f8f02e6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368061
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
This commit is contained in:
Kallen Tu 2024-05-31 17:39:54 +00:00 committed by Commit Queue
parent 8cb19d85f0
commit fcfc66f834
3 changed files with 80 additions and 0 deletions

View file

@ -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
}

View file

@ -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;
}

View file

@ -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);
}