-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zekun Wang
committed
Jun 13, 2024
1 parent
836b4c1
commit 71bdddd
Showing
15 changed files
with
324 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
third_party/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
23 changes: 23 additions & 0 deletions
23
.../move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_invalid.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
23 changes: 23 additions & 0 deletions
23
...move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_invalid.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { | ||
|
||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...ty/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_valid.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
13 changes: 13 additions & 0 deletions
13
...y/move/move-compiler-v2/tests/visibility-checker/mix_friend_package_visibility_valid.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { | ||
|
||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
36 changes: 36 additions & 0 deletions
36
third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...arty/move/move-compiler-v2/tests/visibility-checker/package_visibility_already_friend.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
33 changes: 33 additions & 0 deletions
33
...rty/move/move-compiler-v2/tests/visibility-checker/package_visibility_already_friend.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { | ||
|
||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_cycle.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
11 changes: 11 additions & 0 deletions
11
third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_cycle.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module 0x42::A { | ||
public(package) fun foo() { | ||
0x42::B::foo() | ||
} | ||
} | ||
|
||
module 0x42::B { | ||
public(package) fun foo() { | ||
0x42::A::foo() | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_diff_addr.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 │ │ } | ||
│ ╰─^ |
20 changes: 20 additions & 0 deletions
20
third_party/move/move-compiler-v2/tests/visibility-checker/package_visibility_diff_addr.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
third_party/move/move-compiler-v2/tests/visibility-checker/visibility_complex.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
23 changes: 23 additions & 0 deletions
23
third_party/move/move-compiler-v2/tests/visibility-checker/visibility_complex.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |