From 36ad405ce29cbbb839828e8eebd1f160226e3554 Mon Sep 17 00:00:00 2001 From: "Sergey G. Grekhov" Date: Mon, 2 Sep 2024 16:18:24 +0300 Subject: [PATCH] #2825. Add enhanced parts tests for top-level declarations and ownership (#2842) Add enhanced parts tests for top-level declarations and ownership. Note that a `part of` directive followed by a `part` directive is currently a syntax error. This will be corrected. --- .../Parts-with-imports/ownership_A01_t01.dart | 38 ++++++++++ .../ownership_A01_t01_part1.dart | 43 +++++++++++ .../ownership_A01_t01_part2.dart | 45 ++++++++++++ .../Parts-with-imports/parts_lib.dart | 39 ++++++++++ .../Parts-with-imports/top_level_A01_t01.dart | 71 +++++++++++++++++++ .../top_level_A01_t01_part1.dart | 67 +++++++++++++++++ .../top_level_A01_t01_part2.dart | 66 +++++++++++++++++ .../Parts-with-imports/top_level_A01_t02.dart | 71 +++++++++++++++++++ .../top_level_A01_t02_part1.dart | 67 +++++++++++++++++ .../top_level_A01_t02_part2.dart | 66 +++++++++++++++++ .../Parts-with-imports/top_level_A02_t01.dart | 47 ++++++++++++ .../top_level_A02_t01_part1.dart | 29 ++++++++ .../top_level_A02_t01_part2.dart | 27 +++++++ 13 files changed, 676 insertions(+) create mode 100644 LanguageFeatures/Parts-with-imports/ownership_A01_t01.dart create mode 100644 LanguageFeatures/Parts-with-imports/ownership_A01_t01_part1.dart create mode 100644 LanguageFeatures/Parts-with-imports/ownership_A01_t01_part2.dart create mode 100644 LanguageFeatures/Parts-with-imports/parts_lib.dart create mode 100644 LanguageFeatures/Parts-with-imports/top_level_A01_t01.dart create mode 100644 LanguageFeatures/Parts-with-imports/top_level_A01_t01_part1.dart create mode 100644 LanguageFeatures/Parts-with-imports/top_level_A01_t01_part2.dart create mode 100644 LanguageFeatures/Parts-with-imports/top_level_A01_t02.dart create mode 100644 LanguageFeatures/Parts-with-imports/top_level_A01_t02_part1.dart create mode 100644 LanguageFeatures/Parts-with-imports/top_level_A01_t02_part2.dart create mode 100644 LanguageFeatures/Parts-with-imports/top_level_A02_t01.dart create mode 100644 LanguageFeatures/Parts-with-imports/top_level_A02_t01_part1.dart create mode 100644 LanguageFeatures/Parts-with-imports/top_level_A02_t01_part2.dart diff --git a/LanguageFeatures/Parts-with-imports/ownership_A01_t01.dart b/LanguageFeatures/Parts-with-imports/ownership_A01_t01.dart new file mode 100644 index 0000000000..3a36aa1c8b --- /dev/null +++ b/LanguageFeatures/Parts-with-imports/ownership_A01_t01.dart @@ -0,0 +1,38 @@ +// 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 The unit of ownership is the library. It’s quite possible for one +/// part file to introduce a conflict with another part file. It always was, but +/// there are new ways too. If that happens, the library owner, who most likely +/// introduced the problem, is expected to fix it. There is no attempt to hide +/// name conflicts between declarations in separate tree-branches of the library +/// structure. +/// +/// @description Check that it is a compile-time error if different part files +/// have non-augmenting declarations with the same name. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enhanced-parts + +part 'ownership_A01_t01_part1.dart'; + +String variable = "variable main"; +String get getter => "getter main"; +String function() => "function main"; + +class C {} +mixin M {} +class A {} +extension Ext on A {} +extension type ET(int _) {} + +main() { + print(variable); + print(getter); + print(function); + print(C); + print(M); + print(A); + print(ET); +} diff --git a/LanguageFeatures/Parts-with-imports/ownership_A01_t01_part1.dart b/LanguageFeatures/Parts-with-imports/ownership_A01_t01_part1.dart new file mode 100644 index 0000000000..bedb0e2d4a --- /dev/null +++ b/LanguageFeatures/Parts-with-imports/ownership_A01_t01_part1.dart @@ -0,0 +1,43 @@ +// 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 The unit of ownership is the library. It’s quite possible for one +/// part file to introduce a conflict with another part file. It always was, but +/// there are new ways too. If that happens, the library owner, who most likely +/// introduced the problem, is expected to fix it. There is no attempt to hide +/// name conflicts between declarations in separate tree-branches of the library +/// structure. +/// +/// @description Check that it is a compile-time error if different part files +/// have non-augmenting declarations with the same name. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enhanced-parts + +part of 'ownership_A01_t01.dart'; +part 'ownership_A01_t01_part2.dart'; + +String variable = "variable part1"; +// ^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +String get getter => "getter part1"; +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +class C {} +// ^ +// [analyzer] unspecified +// [cfe] unspecified +mixin M {} +// ^ +// [analyzer] unspecified +// [cfe] unspecified + +void set setter(String _) {} + +enum E { + e0; +} diff --git a/LanguageFeatures/Parts-with-imports/ownership_A01_t01_part2.dart b/LanguageFeatures/Parts-with-imports/ownership_A01_t01_part2.dart new file mode 100644 index 0000000000..5b82d7e403 --- /dev/null +++ b/LanguageFeatures/Parts-with-imports/ownership_A01_t01_part2.dart @@ -0,0 +1,45 @@ +// 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 The unit of ownership is the library. It’s quite possible for one +/// part file to introduce a conflict with another part file. It always was, but +/// there are new ways too. If that happens, the library owner, who most likely +/// introduced the problem, is expected to fix it. There is no attempt to hide +/// name conflicts between declarations in separate tree-branches of the library +/// structure. +/// +/// @description Check that it is a compile-time error if different part files +/// have non-augmenting declarations with the same name. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enhanced-parts + +part of 'ownership_A01_t01_part1.dart'; + +String function() => "function part2"; +// ^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +void set setter(String _) {} +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +extension Ext on A {} +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + +enum E { +// ^ +// [analyzer] unspecified +// [cfe] unspecified + e0; +} + +extension type ET(int _) {} +// ^^ +// [analyzer] unspecified +// [cfe] unspecified diff --git a/LanguageFeatures/Parts-with-imports/parts_lib.dart b/LanguageFeatures/Parts-with-imports/parts_lib.dart new file mode 100644 index 0000000000..0f525db2e8 --- /dev/null +++ b/LanguageFeatures/Parts-with-imports/parts_lib.dart @@ -0,0 +1,39 @@ +// 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 Common library for "Parts with imports" tests. +/// +/// @description Common library for "Parts with imports" tests. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enhanced-parts + +library parts_lib; + +String log = ""; + +String libVar = "libVar"; +String get libGetter => "libGetter"; +void set libSetter(String _) { + log = "libSetter"; +} +String libFunc() => "libFunc"; + +class LibClass { + static final String id = "LibClass"; +} +mixin LibMixin { + static final String id = "LibMixin"; +} +enum LibEnum { + e0; + static final String id = "LibEnum"; +} +class A {} +extension LibExt on A { + static final String id = "LibExt"; +} +extension type LibET(int _) { + static final String id = "LibET"; +} diff --git a/LanguageFeatures/Parts-with-imports/top_level_A01_t01.dart b/LanguageFeatures/Parts-with-imports/top_level_A01_t01.dart new file mode 100644 index 0000000000..5e76159a24 --- /dev/null +++ b/LanguageFeatures/Parts-with-imports/top_level_A01_t01.dart @@ -0,0 +1,71 @@ +// 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 Library member declarations are library-global: All top-level +/// declarations in the library file and all transitive part files are equal, +/// and are all in scope in every file. They introduce declarations into the +/// library’s declaration scope, which is the most significant scope in all +/// files of the library. If there is any conflict with imported names, +/// top-level declarations win! +/// +/// @description Check that all top-level declarations in the library file and +/// all transitive part files are all in scope in every file. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enhanced-parts + +import '../../Utils/expect.dart'; +part 'top_level_A01_t01_part1.dart'; + +String mainVar = "mainVar"; +String get mainGetter => "mainGetter"; +void set mainSetter(String _) {} +String mainFunc() => "mainFunc"; + +class MainClass { + static final id = "MainClass"; +} + +mixin MainMixin { + static final id = "MainMixin"; +} + +enum MainEnum { + e0; + static final id = "MainEnum"; +} + +class A {} + +extension MainExt on A { + static final id = "MainExt"; +} + +extension type MainET(int _) { + static final id = "MainET"; +} + +main() { + Expect.equals("part1Var", part1Var); + Expect.equals("part1Getter", part1Getter); + part1Setter = "x"; + Expect.equals("part1Func", part1Func); + Expect.equals("Part1Class", Part1Class.id); + Expect.equals("Part1Mixin", Part1Mixin.id); + Expect.equals("Part1Enum", Part1Enum.id); + Expect.equals("Part1Ext", Part1Ext.id); + Expect.equals("Part1ET", Part1ET.id); + + Expect.equals("part2Var", part2Var); + Expect.equals("part2Getter", part2Getter); + part2Setter = "x"; + Expect.equals("part2Func", part2Func); + Expect.equals("Part2Class", Part2Class.id); + Expect.equals("Part2Mixin", Part2Mixin.id); + Expect.equals("Part2Enum", Part2Enum.id); + Expect.equals("Part2Ext", Part2Ext.id); + Expect.equals("Part2ET", Part2ET.id); + testPart1(); + testPart2(); +} diff --git a/LanguageFeatures/Parts-with-imports/top_level_A01_t01_part1.dart b/LanguageFeatures/Parts-with-imports/top_level_A01_t01_part1.dart new file mode 100644 index 0000000000..c68e4d8056 --- /dev/null +++ b/LanguageFeatures/Parts-with-imports/top_level_A01_t01_part1.dart @@ -0,0 +1,67 @@ +// 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 Library member declarations are library-global: All top-level +/// declarations in the library file and all transitive part files are equal, +/// and are all in scope in every file. They introduce declarations into the +/// library’s declaration scope, which is the most significant scope in all +/// files of the library. If there is any conflict with imported names, +/// top-level declarations win! +/// +/// @description Check that all top-level declarations in the library file and +/// all transitive part files are all in scope in every file. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enhanced-parts + +part of 'top_level_A01_t01.dart'; +part 'top_level_A01_t01_part2.dart'; + +String part1Var = "part1Var"; +String get part1Getter => "part1Getter"; +void set part1Setter(String _) {} +String part1Func() => "part1Func"; + +class Part1Class { + static final id = "Part1Class"; +} + +mixin Part1Mixin { + static final id = "Part1Mixin"; +} + +enum Part1Enum { + e0; + static final id = "Part1Enum"; +} + +extension Part1Ext on A { + static final id = "Part1Ext"; +} + +extension type Part1ET(int _) { + static final id = "Part1ET"; +} + +testPart1() { + Expect.equals("mainVar", mainVar); + Expect.equals("mainGetter", mainGetter); + mainSetter = "x"; + Expect.equals("mainFunc", mainFunc); + Expect.equals("MainClass", MainClass.id); + Expect.equals("MainMixin", MainMixin.id); + Expect.equals("MainEnum", MainEnum.id); + Expect.equals("MainExt", MainExt.id); + Expect.equals("MainET", MainET.id); + + Expect.equals("part2Var", part2Var); + Expect.equals("part2Getter", part2Getter); + part2Setter = "x"; + Expect.equals("part2Func", part2Func); + Expect.equals("Part2Class", Part2Class.id); + Expect.equals("Part2Mixin", Part2Mixin.id); + Expect.equals("Part2Enum", Part2Enum.id); + Expect.equals("Part2Ext", Part2Ext.id); + Expect.equals("Part2ET", Part2ET.id); +} diff --git a/LanguageFeatures/Parts-with-imports/top_level_A01_t01_part2.dart b/LanguageFeatures/Parts-with-imports/top_level_A01_t01_part2.dart new file mode 100644 index 0000000000..152407b84e --- /dev/null +++ b/LanguageFeatures/Parts-with-imports/top_level_A01_t01_part2.dart @@ -0,0 +1,66 @@ +// 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 Library member declarations are library-global: All top-level +/// declarations in the library file and all transitive part files are equal, +/// and are all in scope in every file. They introduce declarations into the +/// library’s declaration scope, which is the most significant scope in all +/// files of the library. If there is any conflict with imported names, +/// top-level declarations win! +/// +/// @description Check that all top-level declarations in the library file and +/// all transitive part files are all in scope in every file. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enhanced-parts + +part of 'top_level_A01_t01_part1.dart'; + +String part2Var = "part2Var"; +String get part2Getter => "part2Getter"; +void set part2Setter(String _) {} +String part2Func() => "part2Func"; + +class Part2Class { + static final id = "Part2Class"; +} + +mixin Part2Mixin { + static final id = "Part2Mixin"; +} + +enum Part2Enum { + e0; + static final id = "Part2Enum"; +} + +extension Part2Ext on A { + static final id = "Part2Ext"; +} + +extension type Part2ET(int _) { + static final id = "Part2ET"; +} + +testPart2() { + Expect.equals("mainVar", mainVar); + Expect.equals("mainGetter", mainGetter); + mainSetter = "x"; + Expect.equals("mainFunc", mainFunc); + Expect.equals("MainClass", MainClass.id); + Expect.equals("MainMixin", MainMixin.id); + Expect.equals("MainEnum", MainEnum.id); + Expect.equals("MainExt", MainExt.id); + Expect.equals("MainET", MainET.id); + + Expect.equals("part1Var", part1Var); + Expect.equals("part1Getter", part1Getter); + part1Setter = "x"; + Expect.equals("part1Func", part1Func); + Expect.equals("Part1Class", Part1Class.id); + Expect.equals("Part1Mixin", Part1Mixin.id); + Expect.equals("Part1Enum", Part1Enum.id); + Expect.equals("Part1Ext", Part1Ext.id); + Expect.equals("Part1ET", Part1ET.id); +} diff --git a/LanguageFeatures/Parts-with-imports/top_level_A01_t02.dart b/LanguageFeatures/Parts-with-imports/top_level_A01_t02.dart new file mode 100644 index 0000000000..f2d710dd00 --- /dev/null +++ b/LanguageFeatures/Parts-with-imports/top_level_A01_t02.dart @@ -0,0 +1,71 @@ +// 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 Library member declarations are library-global: All top-level +/// declarations in the library file and all transitive part files are equal, +/// and are all in scope in every file. They introduce declarations into the +/// library’s declaration scope, which is the most significant scope in all +/// files of the library. If there is any conflict with imported names, +/// top-level declarations win! +/// +/// @description Check that all top-level declarations in the library file and +/// all transitive part files are all in scope in every file. Test private names +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enhanced-parts + +import '../../Utils/expect.dart'; +part 'top_level_A01_t02_part1.dart'; + +String _mainVar = "mainVar"; +String get _mainGetter => "mainGetter"; +void set _mainSetter(String _) {} +String _mainFunc() => "mainFunc"; + +class _MainClass { + static final id = "MainClass"; +} + +mixin _MainMixin { + static final id = "MainMixin"; +} + +enum _MainEnum { + e0; + static final id = "MainEnum"; +} + +class A {} + +extension _MainExt on A { + static final id = "MainExt"; +} + +extension type _MainET(int _) { + static final id = "MainET"; +} + +main() { + Expect.equals("part1Var", _part1Var); + Expect.equals("part1Getter", _part1Getter); + _part1Setter = "x"; + Expect.equals("part1Func", _part1Func); + Expect.equals("Part1Class", _Part1Class.id); + Expect.equals("Part1Mixin", _Part1Mixin.id); + Expect.equals("Part1Enum", _Part1Enum.id); + Expect.equals("Part1Ext", _Part1Ext.id); + Expect.equals("Part1ET", _Part1ET.id); + + Expect.equals("part2Var", _part2Var); + Expect.equals("part2Getter", _part2Getter); + _part2Setter = "x"; + Expect.equals("part2Func", _part2Func); + Expect.equals("Part2Class", _Part2Class.id); + Expect.equals("Part2Mixin", _Part2Mixin.id); + Expect.equals("Part2Enum", _Part2Enum.id); + Expect.equals("Part2Ext", _Part2Ext.id); + Expect.equals("Part2ET", _Part2ET.id); + testPart1(); + testPart2(); +} diff --git a/LanguageFeatures/Parts-with-imports/top_level_A01_t02_part1.dart b/LanguageFeatures/Parts-with-imports/top_level_A01_t02_part1.dart new file mode 100644 index 0000000000..16399fcf5a --- /dev/null +++ b/LanguageFeatures/Parts-with-imports/top_level_A01_t02_part1.dart @@ -0,0 +1,67 @@ +// 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 Library member declarations are library-global: All top-level +/// declarations in the library file and all transitive part files are equal, +/// and are all in scope in every file. They introduce declarations into the +/// library’s declaration scope, which is the most significant scope in all +/// files of the library. If there is any conflict with imported names, +/// top-level declarations win! +/// +/// @description Check that all top-level declarations in the library file and +/// all transitive part files are all in scope in every file. Test private names +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enhanced-parts + +part of 'top_level_A01_t02.dart'; +part 'top_level_A01_t02_part2.dart'; + +String _part1Var = "part1Var"; +String get _part1Getter => "part1Getter"; +void set _part1Setter(String _) {} +String _part1Func() => "part1Func"; + +class _Part1Class { + static final id = "Part1Class"; +} + +mixin _Part1Mixin { + static final id = "Part1Mixin"; +} + +enum _Part1Enum { + e0; + static final id = "Part1Enum"; +} + +extension _Part1Ext on A { + static final id = "Part1Ext"; +} + +extension type _Part1ET(int _) { + static final id = "Part1ET"; +} + +testPart1() { + Expect.equals("mainVar", _mainVar); + Expect.equals("mainGetter", _mainGetter); + _mainSetter = "x"; + Expect.equals("mainFunc", _mainFunc); + Expect.equals("MainClass", _MainClass.id); + Expect.equals("MainMixin", _MainMixin.id); + Expect.equals("MainEnum", _MainEnum.id); + Expect.equals("MainExt", _MainExt.id); + Expect.equals("MainET", _MainET.id); + + Expect.equals("part2Var", _part2Var); + Expect.equals("part2Getter", _part2Getter); + _part2Setter = "x"; + Expect.equals("part2Func", _part2Func); + Expect.equals("Part2Class", _Part2Class.id); + Expect.equals("Part2Mixin", _Part2Mixin.id); + Expect.equals("Part2Enum", _Part2Enum.id); + Expect.equals("Part2Ext", _Part2Ext.id); + Expect.equals("Part2ET", _Part2ET.id); +} diff --git a/LanguageFeatures/Parts-with-imports/top_level_A01_t02_part2.dart b/LanguageFeatures/Parts-with-imports/top_level_A01_t02_part2.dart new file mode 100644 index 0000000000..537fa79f71 --- /dev/null +++ b/LanguageFeatures/Parts-with-imports/top_level_A01_t02_part2.dart @@ -0,0 +1,66 @@ +// 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 Library member declarations are library-global: All top-level +/// declarations in the library file and all transitive part files are equal, +/// and are all in scope in every file. They introduce declarations into the +/// library’s declaration scope, which is the most significant scope in all +/// files of the library. If there is any conflict with imported names, +/// top-level declarations win! +/// +/// @description Check that all top-level declarations in the library file and +/// all transitive part files are all in scope in every file. Test private names +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enhanced-parts + +part of 'top_level_A01_t02_part1.dart'; + +String _part2Var = "part2Var"; +String get _part2Getter => "part2Getter"; +void set _part2Setter(String _) {} +String _part2Func() => "part2Func"; + +class _Part2Class { + static final id = "Part2Class"; +} + +mixin _Part2Mixin { + static final id = "Part2Mixin"; +} + +enum _Part2Enum { + e0; + static final id = "Part2Enum"; +} + +extension _Part2Ext on A { + static final id = "Part2Ext"; +} + +extension type _Part2ET(int _) { + static final id = "Part2ET"; +} + +testPart2() { + Expect.equals("mainVar", _mainVar); + Expect.equals("mainGetter", _mainGetter); + _mainSetter = "x"; + Expect.equals("mainFunc", _mainFunc); + Expect.equals("MainClass", _MainClass.id); + Expect.equals("MainMixin", _MainMixin.id); + Expect.equals("MainEnum", _MainEnum.id); + Expect.equals("MainExt", _MainExt.id); + Expect.equals("MainET", _MainET.id); + + Expect.equals("part1Var", _part1Var); + Expect.equals("part1Getter", _part1Getter); + _part1Setter = "x"; + Expect.equals("part1Func", _part1Func); + Expect.equals("Part1Class", _Part1Class.id); + Expect.equals("Part1Mixin", _Part1Mixin.id); + Expect.equals("Part1Enum", _Part1Enum.id); + Expect.equals("Part1Ext", _Part1Ext.id); + Expect.equals("Part1ET", _Part1ET.id); +} diff --git a/LanguageFeatures/Parts-with-imports/top_level_A02_t01.dart b/LanguageFeatures/Parts-with-imports/top_level_A02_t01.dart new file mode 100644 index 0000000000..ce0359ba46 --- /dev/null +++ b/LanguageFeatures/Parts-with-imports/top_level_A02_t01.dart @@ -0,0 +1,47 @@ +// 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 Library member declarations are library-global: All top-level +/// declarations in the library file and all transitive part files are equal, +/// and are all in scope in every file. They introduce declarations into the +/// library’s declaration scope, which is the most significant scope in all +/// files of the library. If there is any conflict with imported names, +/// top-level declarations win! +/// +/// @description Check that if there is a conflict with imported names, +/// top-level declarations win. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enhanced-parts + +import 'parts_lib.dart'; +import '../../Utils/expect.dart'; + +part 'top_level_A02_t01_part1.dart'; + +String libVar = "libVar main"; +String libFunc() => "libFunc main"; + +mixin LibMixin { + static final id = "LibMixin main"; +} + +class A {} + +extension LibExt on A { + static final id = "LibExt main"; +} + +main() { + Expect.equals("libVar main", libVar); + Expect.equals("libGetter part1", libGetter); + libSetter = "x"; + Expect.equals("libSetter part2", log); + Expect.equals("libFunc main", libFunc); + Expect.equals("LibClass part1", LibClass.id); + Expect.equals("LibMixin main", LibMixin.id); + Expect.equals("LibEnum part2", LibEnum.id); + Expect.equals("LibExt main", LibExt.id); + Expect.equals("LibET part1", LibET.id); +} diff --git a/LanguageFeatures/Parts-with-imports/top_level_A02_t01_part1.dart b/LanguageFeatures/Parts-with-imports/top_level_A02_t01_part1.dart new file mode 100644 index 0000000000..6366d342b3 --- /dev/null +++ b/LanguageFeatures/Parts-with-imports/top_level_A02_t01_part1.dart @@ -0,0 +1,29 @@ +// 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 Library member declarations are library-global: All top-level +/// declarations in the library file and all transitive part files are equal, +/// and are all in scope in every file. They introduce declarations into the +/// library’s declaration scope, which is the most significant scope in all +/// files of the library. If there is any conflict with imported names, +/// top-level declarations win! +/// +/// @description Check that if there is a conflict with imported names, +/// top-level declarations win. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enhanced-parts + +part of 'top_level_A02_t01.dart'; +part 'top_level_A02_t01_part2.dart'; + +String get libGetter => "libGetter part1"; + +class LibClass { + static final id = "LibClass part1"; +} + +extension type LibET(int _) { + static final id = "LibET part1"; +} diff --git a/LanguageFeatures/Parts-with-imports/top_level_A02_t01_part2.dart b/LanguageFeatures/Parts-with-imports/top_level_A02_t01_part2.dart new file mode 100644 index 0000000000..b6f4131209 --- /dev/null +++ b/LanguageFeatures/Parts-with-imports/top_level_A02_t01_part2.dart @@ -0,0 +1,27 @@ +// 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 Library member declarations are library-global: All top-level +/// declarations in the library file and all transitive part files are equal, +/// and are all in scope in every file. They introduce declarations into the +/// library’s declaration scope, which is the most significant scope in all +/// files of the library. If there is any conflict with imported names, +/// top-level declarations win! +/// +/// @description Check that if there is a conflict with imported names, +/// top-level declarations win. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enhanced-parts + +part of 'top_level_A02_t01_part1.dart'; + +void set libSetter(String _) { + log = "libSetter part2"; +} + +enum LibEnum { + e0; + static final id = "LibEnum part2"; +}