Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zekun Wang committed Jun 13, 2024
1 parent 836b4c1 commit 71bdddd
Show file tree
Hide file tree
Showing 15 changed files with 324 additions and 0 deletions.
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
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
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() {

}
}
}
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
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() {

}
}
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
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()
}
}
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
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() {

}
}
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'
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()
}
}
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 │ │ }
│ ╰─^
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()
}
}
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
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();
}
}

0 comments on commit 71bdddd

Please sign in to comment.