diff --git a/third_party/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility.exp b/third_party/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility.exp new file mode 100644 index 00000000000000..250791c736faff --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility.exp @@ -0,0 +1,23 @@ + +Diagnostics: +error: Cannot use both package and friend visibility in the same module + ┌─ tests/visibility-checker/mix_friend_package_visibility.move:7:3 + │ +3 │ public(package) fun foo() { + │ --------------- package visibility declared here + · +7 │ public(friend) fun bar() { + │ ^^^^^^^^^^^^^^ + │ │ + │ friend visibility declared here + +error: Cannot use both package and friend visibility in the same module + ┌─ tests/visibility-checker/mix_friend_package_visibility.move:15:3 + │ +15 │ public(friend) fun foo() { + │ ^^^^^^^^^^^^^^ + │ │ + │ friend visibility declared here + · +19 │ public(package) fun bar() { + │ --------------- package visibility declared here diff --git a/third_party/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_invalid.exp b/third_party/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_invalid.exp new file mode 100644 index 00000000000000..3abc38440d43ee --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_invalid.exp @@ -0,0 +1,23 @@ + +Diagnostics: +error: Cannot use both package and friend visibility in the same module + ┌─ tests/visibility-checker/mix_friend_package_visibility_invalid.move:7:3 + │ +3 │ public(package) fun foo() { + │ --------------- package visibility declared here + · +7 │ public(friend) fun bar() { + │ ^^^^^^^^^^^^^^ + │ │ + │ friend visibility declared here + +error: Cannot use both package and friend visibility in the same module + ┌─ tests/visibility-checker/mix_friend_package_visibility_invalid.move:15:3 + │ +15 │ public(friend) fun foo() { + │ ^^^^^^^^^^^^^^ + │ │ + │ friend visibility declared here + · +19 │ public(package) fun bar() { + │ --------------- package visibility declared here diff --git a/third_party/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_invalid.move b/third_party/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_invalid.move new file mode 100644 index 00000000000000..5526ab6535d323 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_invalid.move @@ -0,0 +1,23 @@ +address 0x42 { + module A { + public(package) fun foo() { + + } + + public(friend) fun bar() { + + } + } +} + +address 0x43 { + module A { + public(friend) fun foo() { + + } + + public(package) fun bar() { + + } + } +} diff --git a/third_party/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_valid.exp b/third_party/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_valid.exp new file mode 100644 index 00000000000000..cd4161e3b94620 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_valid.exp @@ -0,0 +1,12 @@ +// -- Model dump before bytecode pipeline +module 0x42::B { + friend fun foo() { + Tuple() + } +} // end 0x42::B +module 0x42::A { + friend fun foo() { + B::foo(); + Tuple() + } +} // end 0x42::A diff --git a/third_party/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_valid.move b/third_party/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_valid.move new file mode 100644 index 00000000000000..0344e725e4754b --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_valid.move @@ -0,0 +1,13 @@ +// It's ok to use (public)friend and public(package) in different modules + +module 0x42::A { + public(friend) fun foo() { + 0x42::B::foo(); + } +} + +module 0x42::B { + public(package) fun foo() { + + } +} diff --git a/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility.exp b/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility.exp new file mode 100644 index 00000000000000..1423e7fb8a51c1 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility.exp @@ -0,0 +1,33 @@ +// -- Model dump before bytecode pipeline +module 0x42::A { + friend fun bar() { + Tuple() + } + private fun foo() { + Tuple() + } +} // end 0x42::A +module 0x42::B { + use 0x42::A; // resolved as: 0x42::A + public fun bar() { + A::bar() + } + friend fun foo() { + A::bar() + } + private fun baz() { + A::bar() + } +} // end 0x42::B +module 0x42::C { + use 0x42::B; // resolved as: 0x42::B + public fun bar() { + B::foo() + } + friend fun foo() { + B::foo() + } + private fun baz() { + B::foo() + } +} // end 0x42::C diff --git a/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility.move b/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility.move new file mode 100644 index 00000000000000..d4d73b266c0f30 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility.move @@ -0,0 +1,36 @@ +module 0x42::A { + fun foo() {} + public(package) fun bar() {} +} + +module 0x42::B { + use 0x42::A; + + public(package) fun foo() { + A::bar() + } + + public fun bar() { + A::bar() + } + + fun baz() { + A::bar() + } +} + +module 0x42::C { + use 0x42::B; + + public(package) fun foo() { + B::foo() + } + + public fun bar() { + B::foo() + } + + fun baz() { + B::foo() + } +} diff --git a/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_already_friend.exp b/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_already_friend.exp new file mode 100644 index 00000000000000..1b8228696ef648 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_already_friend.exp @@ -0,0 +1,29 @@ +// -- Model dump before bytecode pipeline +module 0x42::C { + friend fun bar() { + Tuple() + } + friend fun foo() { + C::bar() + } +} // end 0x42::C +module 0x42::A { + friend fun bar() { + Tuple() + } + private fun foo() { + Tuple() + } +} // end 0x42::A +module 0x42::B { + use 0x42::A; // resolved as: 0x42::A + public fun bar() { + A::bar() + } + friend fun foo() { + A::bar() + } + private fun baz() { + A::bar() + } +} // end 0x42::B diff --git a/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_already_friend.move b/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_already_friend.move new file mode 100644 index 00000000000000..273f1331714289 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_already_friend.move @@ -0,0 +1,33 @@ +module 0x42::A { + // check we don't add duplicate `friend 0x42::B;` + // during the transformation + friend 0x42::B; + fun foo() {} + public(package) fun bar() {} +} + +module 0x42::B { + use 0x42::A; + + public(package) fun foo() { + A::bar() + } + + public fun bar() { + A::bar() + } + + fun baz() { + A::bar() + } +} + +module 0x42::C { + public(package) fun foo() { + bar() + } + + public(package) fun bar() { + + } +} diff --git a/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_cycle.exp b/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_cycle.exp new file mode 100644 index 00000000000000..1671814a56bc5f --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_cycle.exp @@ -0,0 +1,10 @@ + +Diagnostics: +error: invalid 'module' declaration + ┌─ tests/visibility-checker/package_visibility_cycle.move:3:3 + │ +3 │ 0x42::B::foo() + │ ^^^^^^^^^^^^ '0x42::B' uses '0x42::A'. This 'use' relationship creates a dependency cycle. + · +9 │ 0x42::A::foo() + │ ------------ '0x42::A' uses '0x42::B' diff --git a/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_cycle.move b/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_cycle.move new file mode 100644 index 00000000000000..c9e2a9524a7380 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_cycle.move @@ -0,0 +1,11 @@ +module 0x42::A { + public(package) fun foo() { + 0x42::B::foo() + } +} + +module 0x42::B { + public(package) fun foo() { + 0x42::A::foo() + } +} diff --git a/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_diff_addr.exp b/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_diff_addr.exp new file mode 100644 index 00000000000000..fb1032d0371f54 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_diff_addr.exp @@ -0,0 +1,10 @@ + +Diagnostics: +error: friend modules of `0x42::A` must have the same address, but the declared friend module `0x43::B` has a different address + ┌─ tests/visibility-checker/package_visibility_diff_addr.move:1:1 + │ +1 │ ╭ module 0x42::A { +2 │ │ fun foo() {} +3 │ │ public(package) fun bar() {} +4 │ │ } + │ ╰─^ diff --git a/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_diff_addr.move b/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_diff_addr.move new file mode 100644 index 00000000000000..e4aa5308970ff6 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_diff_addr.move @@ -0,0 +1,20 @@ +module 0x42::A { + fun foo() {} + public(package) fun bar() {} +} + +module 0x43::B { + use 0x42::A; + + public(package) fun foo() { + A::bar() + } + + public fun bar() { + A::bar() + } + + fun baz() { + A::bar() + } +} diff --git a/third_party/move/move-compiler-v2/tests/visibility-checker/visibility_complex.exp b/third_party/move/move-compiler-v2/tests/visibility-checker/visibility_complex.exp new file mode 100644 index 00000000000000..6cf8b10e577f74 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/visibility-checker/visibility_complex.exp @@ -0,0 +1,25 @@ +// -- Model dump before bytecode pipeline +module 0x42::B { + friend fun foo() { + Tuple() + } +} // end 0x42::B +module 0x42::A { + friend fun foo() { + Tuple() + } +} // end 0x42::A +module 0x42::C { + friend fun foo() { + A::foo(); + B::foo(); + Tuple() + } +} // end 0x42::C +module 0x42::D { + friend fun bar() { + B::foo(); + C::foo(); + Tuple() + } +} // end 0x42::D diff --git a/third_party/move/move-compiler-v2/tests/visibility-checker/visibility_complex.move b/third_party/move/move-compiler-v2/tests/visibility-checker/visibility_complex.move new file mode 100644 index 00000000000000..d3d85b905f7e66 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/visibility-checker/visibility_complex.move @@ -0,0 +1,23 @@ +module 0x42::A { + friend 0x42::C; + public(friend) fun foo() {} +} + +module 0x42::B { + public(package) fun foo() {} +} + +module 0x42::C { + friend 0x42::D; + public(friend) fun foo() { + 0x42::A::foo(); + 0x42::B::foo(); + } +} + +module 0x42::D { + public(package) fun bar() { + 0x42::B::foo(); + 0x42::C::foo(); + } +}