From 379f6f89cc067032c7236351b870d83ef46f3ba5 Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Wed, 6 Mar 2024 09:17:06 +0200 Subject: [PATCH] #2559. Add tests for augment libraries visibility --- .../augmentation_libraries_lib.dart | 12 ++++ .../defining_augmentation_A01_t01.dart | 56 +++++++++++++++ .../defining_augmentation_A01_t01_lib.dart | 70 +++++++++++++++++++ .../defining_augmentation_A01_t02.dart | 58 +++++++++++++++ .../defining_augmentation_A01_t02_lib.dart | 70 +++++++++++++++++++ .../defining_augmentation_A02_t01.dart | 22 ++++++ .../defining_augmentation_A02_t01_lib.dart | 17 +++++ .../defining_augmentation_A02_t02.dart | 23 ++++++ .../defining_augmentation_A02_t02_lib.dart | 18 +++++ .../defining_augmentation_A02_t03.dart | 22 ++++++ .../defining_augmentation_A02_t03_lib.dart | 17 +++++ .../defining_augmentation_A02_t03_main.dart | 16 +++++ .../defining_augmentation_A02_t04.dart | 22 ++++++ .../defining_augmentation_A02_t04_lib.dart | 18 +++++ .../defining_augmentation_A02_t04_main.dart | 16 +++++ .../defining_augmentation_A02_t05.dart | 22 ++++++ .../defining_augmentation_A02_t05_main.dart | 17 +++++ 17 files changed, 496 insertions(+) create mode 100644 LanguageFeatures/Augmentation-libraries/augmentation_libraries_lib.dart create mode 100644 LanguageFeatures/Augmentation-libraries/defining_augmentation_A01_t01.dart create mode 100644 LanguageFeatures/Augmentation-libraries/defining_augmentation_A01_t01_lib.dart create mode 100644 LanguageFeatures/Augmentation-libraries/defining_augmentation_A01_t02.dart create mode 100644 LanguageFeatures/Augmentation-libraries/defining_augmentation_A01_t02_lib.dart create mode 100644 LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t01.dart create mode 100644 LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t01_lib.dart create mode 100644 LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t02.dart create mode 100644 LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t02_lib.dart create mode 100644 LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t03.dart create mode 100644 LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t03_lib.dart create mode 100644 LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t03_main.dart create mode 100644 LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t04.dart create mode 100644 LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t04_lib.dart create mode 100644 LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t04_main.dart create mode 100644 LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t05.dart create mode 100644 LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t05_main.dart diff --git a/LanguageFeatures/Augmentation-libraries/augmentation_libraries_lib.dart b/LanguageFeatures/Augmentation-libraries/augmentation_libraries_lib.dart new file mode 100644 index 0000000000..d834ef0adc --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmentation_libraries_lib.dart @@ -0,0 +1,12 @@ +// 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. + +/// @description Common library for augmentation libraries tests +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +library augmentation_libraries_lib; + +class AL {} diff --git a/LanguageFeatures/Augmentation-libraries/defining_augmentation_A01_t01.dart b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A01_t01.dart new file mode 100644 index 0000000000..5681363ceb --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A01_t01.dart @@ -0,0 +1,56 @@ +// 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. + +/// @assertion Declarations in any augmentation or the main library are visible +/// to all of the others, including private ones. +/// +/// @description Checks that declarations in an augmentation are visible in a +/// main library +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +import '../../Utils/expect.dart'; +import augment 'defining_augmentation_A01_t01_lib.dart'; + +extension on C1 { + String get z => "z"; +} + +extension on _C2 { + String get _z => "_z"; +} + +extension type ET1(C1 id) {} +extension type ET2(_C2 id) {} + +class MA1 = Object with M1; +class MA2 = Object with _M2; + +main() { + Expect.equals("y", C1().y); + Expect.equals("z", C1().z); + Expect.equals("m", MA1().m); + Expect.equals("_y", _C2()._y); + Expect.equals("_z", _C2()._z); + Expect.equals("_m", MA2()._m); + Expect.equals("y", ET1(C1()).id.y); + Expect.equals("_y", ET2(_C2()).id._y); + Expect.equals(E1.e, E1.e.instance); + Expect.equals(_E2.e, _E2.e._instance); + Expect.equals(42, x1); + Expect.equals(42, _x2); + Expect.equals(0, foo1()); + Expect.equals(0, _foo2()); + Expect.equals("bar", [].bar); + Expect.equals("bar", MyList([]).bar); + Expect.equals("_baz", [].baz); + Expect.equals("_baz", _MyList([]).baz); + Expect.equals(42, MyInt(42)); + Expect.equals(42, _MyInt(42)); + Expect.isTrue((Foo1 as dynamic) is Type); + Expect.isTrue((_Foo2 as dynamic) is Type); + Expect.isTrue((C1Alias as dynamic) is Type); + Expect.isTrue((_C2Alias as dynamic) is Type); +} diff --git a/LanguageFeatures/Augmentation-libraries/defining_augmentation_A01_t01_lib.dart b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A01_t01_lib.dart new file mode 100644 index 0000000000..bf75d401e9 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A01_t01_lib.dart @@ -0,0 +1,70 @@ +// 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. + +/// @assertion Declarations in any augmentation or the main library are visible +/// to all of the others, including private ones. +/// +/// @description Checks that declarations in an augmentation are visible in a +/// main library +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +library augment 'defining_augmentation_A01_t01.dart'; + +class C1 { + String get y => "y"; +} + +mixin M1 { + String get m => "m"; +} + +enum E1 { + e; + + E1 get instance => e; +} + +var x1 = 42; + +int foo1() => 0; + +extension MyList on List { + String get bar => "bar"; +} + +extension type MyInt(int id) {} + +typedef void Foo1(); + +typedef C1Alias = C1; + +class _C2 { + String get _y => "_y"; +} + +mixin _M2 { + String get _m => "_m"; +} + +enum _E2 { + e; + + _E2 get _instance => e; +} + +var _x2 = 42; + +int _foo2() => 0; + +extension _MyList on List { + String get baz => "_baz"; +} + +extension type _MyInt(int id2) {} + +typedef void _Foo2(); + +typedef _C2Alias = _C2; diff --git a/LanguageFeatures/Augmentation-libraries/defining_augmentation_A01_t02.dart b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A01_t02.dart new file mode 100644 index 0000000000..0267ecd56b --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A01_t02.dart @@ -0,0 +1,58 @@ +// 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. + +/// @assertion Declarations in any augmentation or the main library are visible +/// to all of the others, including private ones. +/// +/// @description Checks that declarations in a main library are visible in an +/// augmentation library +/// @author sgrekhov22@gmail.com +/// @issue 55103 + +// SharedOptions=--enable-experiment=macros + +library augment 'defining_augmentation_A01_t02_lib.dart'; + +import '../../Utils/expect.dart'; + +extension on C1 { + String get z => "z"; +} + +extension on _C2 { + String get _z => "_z"; +} + +extension type ET1(C1 id) {} +extension type ET2(_C2 id) {} + +class MA1 = Object with M1; +class MA2 = Object with _M2; + +main() { + Expect.equals("y", C1().y); + Expect.equals("z", C1().z); + Expect.equals("m", MA1().m); + Expect.equals("_y", _C2()._y); + Expect.equals("_z", _C2()._z); + Expect.equals("_m", MA2()._m); + Expect.equals("y", ET1(C1()).id.y); + Expect.equals("_y", ET2(_C2()).id._y); + Expect.equals(E1.e, E1.e.instance); + Expect.equals(_E2.e, _E2.e._instance); + Expect.equals(42, x1); + Expect.equals(42, _x2); + Expect.equals(0, foo1()); + Expect.equals(0, _foo2()); + Expect.equals("bar", [].bar); + Expect.equals("bar", MyList([]).bar); + Expect.equals("_baz", [].baz); + Expect.equals("_baz", _MyList([]).baz); + Expect.equals(42, MyInt(42)); + Expect.equals(42, _MyInt(42)); + Expect.isTrue((Foo1 as dynamic) is Type); + Expect.isTrue((_Foo2 as dynamic) is Type); + Expect.isTrue((C1Alias as dynamic) is Type); + Expect.isTrue((_C2Alias as dynamic) is Type); +} diff --git a/LanguageFeatures/Augmentation-libraries/defining_augmentation_A01_t02_lib.dart b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A01_t02_lib.dart new file mode 100644 index 0000000000..471990a534 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A01_t02_lib.dart @@ -0,0 +1,70 @@ +// 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. + +/// @assertion Declarations in any augmentation or the main library are visible +/// to all of the others, including private ones. +/// +/// @description Checks that declarations in a main library are visible in an +/// augmentation library +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +import augment 'defining_augmentation_A01_t02.dart'; + +class C1 { + String get y => "y"; +} + +mixin M1 { + String get m => "m"; +} + +enum E1 { + e; + + E1 get instance => e; +} + +var x1 = 42; + +int foo1() => 0; + +extension MyList on List { + String get bar => "bar"; +} + +extension type MyInt(int id) {} + +typedef void Foo1(); + +typedef C1Alias = C1; + +class _C2 { + String get _y => "_y"; +} + +mixin _M2 { + String get _m => "_m"; +} + +enum _E2 { + e; + + _E2 get _instance => e; +} + +var _x2 = 42; + +int _foo2() => 0; + +extension _MyList on List { + String get baz => "_baz"; +} + +extension type _MyInt(int id2) {} + +typedef void _Foo2(); + +typedef _C2Alias = _C2; diff --git a/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t01.dart b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t01.dart new file mode 100644 index 0000000000..79bb8bda58 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t01.dart @@ -0,0 +1,22 @@ +// 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. + +/// @assertion Augmentations do not share an import scope with the main library +/// or each other. The libraries one augmentation imports are visible only to +/// that file. +/// +/// @description Checks that imports in an augmentation library are not visible +/// in a main library +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +import augment 'defining_augmentation_A02_t01_lib.dart'; + +main() { + print(AL); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} diff --git a/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t01_lib.dart b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t01_lib.dart new file mode 100644 index 0000000000..8dba86870f --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t01_lib.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. + +/// @assertion Augmentations do not share an import scope with the main library +/// or each other. The libraries one augmentation imports are visible only to +/// that file. +/// +/// @description Checks that imports in an augmentation library are not visible +/// in a main library +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +library augment 'defining_augmentation_A02_t01.dart'; + +import 'augmentation_libraries_lib.dart'; diff --git a/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t02.dart b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t02.dart new file mode 100644 index 0000000000..3f6a750d09 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t02.dart @@ -0,0 +1,23 @@ +// 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. + +/// @assertion Augmentations do not share an import scope with the main library +/// or each other. The libraries one augmentation imports are visible only to +/// that file. +/// +/// @description Checks that imports in an augmentation library are not visible +/// in a main library even if an augmentation library exports it +/// @author sgrekhov22@gmail.com +/// @issue 55112 + +// SharedOptions=--enable-experiment=macros + +import augment 'defining_augmentation_A02_t02_lib.dart'; + +main() { + print(AL); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} diff --git a/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t02_lib.dart b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t02_lib.dart new file mode 100644 index 0000000000..98e5e9ead8 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t02_lib.dart @@ -0,0 +1,18 @@ +// 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. + +/// @assertion Augmentations do not share an import scope with the main library +/// or each other. The libraries one augmentation imports are visible only to +/// that file. +/// +/// @description Checks that imports in an augmentation library are not visible +/// in a main library even if an augmentation library exports it +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +library augment 'defining_augmentation_A02_t02.dart'; + +import 'augmentation_libraries_lib.dart'; +export 'augmentation_libraries_lib.dart'; diff --git a/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t03.dart b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t03.dart new file mode 100644 index 0000000000..efb46bdb19 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t03.dart @@ -0,0 +1,22 @@ +// 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. + +/// @assertion Augmentations do not share an import scope with the main library +/// or each other. The libraries one augmentation imports are visible only to +/// that file. +/// +/// @description Checks that imports in an augmentation library are not visible +/// in another augmentation library +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +library augment 'defining_augmentation_A02_t03_main.dart'; + +main() { + print(AL); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} diff --git a/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t03_lib.dart b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t03_lib.dart new file mode 100644 index 0000000000..c974272f39 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t03_lib.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. + +/// @assertion Augmentations do not share an import scope with the main library +/// or each other. The libraries one augmentation imports are visible only to +/// that file. +/// +/// @description Checks that imports in an augmentation library are not visible +/// in another augmentation library +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +library augment 'defining_augmentation_A02_t03_main.dart'; + +import 'augmentation_libraries_lib.dart'; diff --git a/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t03_main.dart b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t03_main.dart new file mode 100644 index 0000000000..0d970e5566 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t03_main.dart @@ -0,0 +1,16 @@ +// 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. + +/// @assertion Augmentations do not share an import scope with the main library +/// or each other. The libraries one augmentation imports are visible only to +/// that file. +/// +/// @description Checks that imports in an augmentation library are not visible +/// in another augmentation library +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +import augment 'defining_augmentation_A02_t03.dart'; +import augment 'defining_augmentation_A02_t03_lib.dart'; diff --git a/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t04.dart b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t04.dart new file mode 100644 index 0000000000..1442e8c02c --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t04.dart @@ -0,0 +1,22 @@ +// 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. + +/// @assertion Augmentations do not share an import scope with the main library +/// or each other. The libraries one augmentation imports are visible only to +/// that file. +/// +/// @description Checks that imports in an augmentation library are not visible +/// in another augmentation library even it exports it +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +library augment 'defining_augmentation_A02_t04_main.dart'; + +main() { + print(AL); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} diff --git a/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t04_lib.dart b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t04_lib.dart new file mode 100644 index 0000000000..aedc22004f --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t04_lib.dart @@ -0,0 +1,18 @@ +// 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. + +/// @assertion Augmentations do not share an import scope with the main library +/// or each other. The libraries one augmentation imports are visible only to +/// that file. +/// +/// @description Checks that imports in an augmentation library are not visible +/// in another augmentation library +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +library augment 'defining_augmentation_A02_t04_main.dart'; + +import 'augmentation_libraries_lib.dart'; +export 'augmentation_libraries_lib.dart'; diff --git a/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t04_main.dart b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t04_main.dart new file mode 100644 index 0000000000..7de3443f5d --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t04_main.dart @@ -0,0 +1,16 @@ +// 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. + +/// @assertion Augmentations do not share an import scope with the main library +/// or each other. The libraries one augmentation imports are visible only to +/// that file. +/// +/// @description Checks that imports in an augmentation library are not visible +/// in another augmentation library even it exports it +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +import augment 'defining_augmentation_A02_t04.dart'; +import augment 'defining_augmentation_A02_t04_lib.dart'; diff --git a/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t05.dart b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t05.dart new file mode 100644 index 0000000000..2c78c28e7d --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t05.dart @@ -0,0 +1,22 @@ +// 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. + +/// @assertion Augmentations do not share an import scope with the main library +/// or each other. The libraries one augmentation imports are visible only to +/// that file. +/// +/// @description Checks that imports from main library are not visible in an +/// augmentation library +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +library augment 'defining_augmentation_A02_t05_main.dart'; + +main() { + print(AL); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} diff --git a/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t05_main.dart b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t05_main.dart new file mode 100644 index 0000000000..2ded231300 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/defining_augmentation_A02_t05_main.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. + +/// @assertion Augmentations do not share an import scope with the main library +/// or each other. The libraries one augmentation imports are visible only to +/// that file. +/// +/// @description Checks that imports from main library are not visible in an +/// augmentation library +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +import augment 'defining_augmentation_A02_t05.dart'; + +import 'augmentation_libraries_lib.dart';