Skip to content

Commit

Permalink
migrate tests (#13150)
Browse files Browse the repository at this point in the history
  • Loading branch information
rahxephon89 authored May 2, 2024
1 parent 66d9efb commit 17937e7
Show file tree
Hide file tree
Showing 82 changed files with 1,050 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

Diagnostics:
error: local `t` of type `M::T` does not have the `drop` ability
┌─ tests/ability-check/v1-borrow-tests/assign_resource.move:5:22
5 │ let t = T{}; &t;
│ ^^ implicitly dropped here since it is no longer used

error: local `t` of type `M::T` does not have the `drop` ability
┌─ tests/ability-check/v1-borrow-tests/assign_resource.move:6:19
6 │ t = T {}; &t;
│ ^^ implicitly dropped here since it is no longer used
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module 0x8675309::M {
struct T {}

fun no() {
let t = T{}; &t;
t = T {}; &t;
}

}

// check: STLOC_UNSAFE_TO_DESTROY_ERROR
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

Diagnostics:
error: cannot return a reference derived from value since it is not a parameter
┌─ tests/ability-check/v1-borrow-tests/return_type_mismatch_and_unused_resource.move:13:9
12 │ let r = &u;
│ -- previous local borrow
13 │ r
│ ^ returned here


Diagnostics:
error: local `x` of type `M::X` does not have the `drop` ability
┌─ tests/ability-check/v1-borrow-tests/return_type_mismatch_and_unused_resource.move:6:9
6 │ &x;
│ ^^ implicitly dropped here since it is no longer used
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module 0x8675309::M {
struct X {}

fun t1(): bool {
let x = X {};
&x;
false
}

fun t2(): &u64 {
let u = 0;
let r = &u;
r
}
}

// check: RET_UNSAFE_TO_DESTROY_ERROR
// check: RET_UNSAFE_TO_DESTROY_ERROR
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

Diagnostics:
error: local `x` of type `M::Cup<M::R>` does not have the `drop` ability
┌─ tests/ability-check/v1-locals/drop_conditional.move:12:9
12 │ &x;
│ ^^ implicitly dropped here since it is no longer used

error: local `x` of type `M::Pair<M::S, M::R>` does not have the `drop` ability
┌─ tests/ability-check/v1-locals/drop_conditional.move:14:9
14 │ &x;
│ ^^ implicitly dropped here since it is no longer used
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
address 0x42 {
module M {

struct Cup<T> has drop { f: T }
struct Pair<T1, T2> has drop { f1: T1, f2: T2 }
struct R {}
struct S has drop {}

// Error on a type that can have the drop ability, but the instantiation does not
fun t() {
let x = Cup<R> { f: R{} };
&x;
let x = Pair<S, R> { f1: S{}, f2: R{} };
&x;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

Diagnostics:
error: local `r` of type `M::R` does not have the `drop` ability
┌─ tests/ability-check/v1-locals/reassign_parameter.move:7:9
7 │ ╭ if (true) {
8 │ │ let R { } = r;
9 │ │ }
│ ╰─────────^ implicitly dropped here since it is no longer used
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module 0x8675309::M {
struct R {}

public fun reassign_parameter(r: R) {
let R { } = r;
r = R {};
if (true) {
let R { } = r;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

Diagnostics:
error: value of type `M::R` does not have the `drop` ability
┌─ tests/ability-check/v1-typing/bind_pop_resource.move:5:13
5 │ let _: R = R{};
│ ^ implicitly dropped here since it is no longer used

error: local `_r` of type `M::R` does not have the `drop` ability
┌─ tests/ability-check/v1-typing/bind_pop_resource.move:8:21
8 │ let _r: R = R{};
│ ^^^ implicitly dropped here since it is no longer used

error: value of type `M::R` does not have the `drop` ability
┌─ tests/ability-check/v1-typing/bind_pop_resource.move:9:13
9 │ let (_, _):(R, R) = (R{}, R{});
│ ^^^^^^ implicitly dropped here since it is no longer used
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module 0x8675309::M {
struct R {}

fun t0() {
let _: R = R{};
// the following is an invalid binding too but its error message will
// not show because the compilation fails early at the typing phase
let _r: R = R{};
let (_, _):(R, R) = (R{}, R{});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

============ bytecode verification succeeded ========
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module 0x8675309::A {
use std::signer;
struct T1 has key {v: u64}

public fun test(account: &signer) acquires T1 {
borrow_global_mut<T1>(signer::address_of(account));
acquires_t1(account);
}

fun acquires_t1(account: &signer) acquires T1 {
T1 { v: _ } = move_from<T1>(signer::address_of(account));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

============ bytecode verification succeeded ========
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module 0x8675309::A {
use std::signer;
struct T1 has key {v: u64}
struct T2 has key {v: u64}

public fun test1(account: &signer) acquires T1, T2 {
let x = borrow_global_mut<T1>(signer::address_of(account));
acquires_t2(account);
move x;
acquires_t1(account);
}

public fun test2(account: &signer) acquires T1, T2 {
borrow_global_mut<T1>(signer::address_of(account));
acquires_t1(account);
acquires_t2(account);
}

public fun test3(account: &signer) acquires T1, T2 {
borrow_global_mut<T1>(signer::address_of(account));
acquires_t2(account);
acquires_t1(account);
}

fun acquires_t1(account: &signer) acquires T1 {
T1 { v: _ } = move_from<T1>(signer::address_of(account))
}

fun acquires_t2(account: &signer) acquires T2 {
T2 { v: _ } = move_from<T2>(signer::address_of(account))
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

============ bytecode verification succeeded ========
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module 0x8675309::A {
use std::signer;
struct T1 has key {v: u64}
struct T2 has key {v: u64}

public fun test1(account: &signer) acquires T1, T2 {
let x = borrow_global_mut<T1>(signer::address_of(account));
let y = get_v(x);
acquires_t2(account);
move y;
acquires_t1(account);
}

public fun test2(account: &signer) acquires T1, T2 {
let x = borrow_global_mut<T1>(signer::address_of(account));
let y = get_v(x);
move y;
acquires_t1(account);
acquires_t2(account);
}

public fun test3(account: &signer) acquires T1, T2 {
let x = borrow_global_mut<T1>(signer::address_of(account));
let y = get_v(x);
move y;
acquires_t2(account);
acquires_t1(account);
}

fun get_v(x: &mut T1): &mut u64 {
&mut x.v
}

fun acquires_t1(account: &signer) acquires T1 {
T1 { v: _ } = move_from<T1>(signer::address_of(account))
}

fun acquires_t2(account: &signer) acquires T2 {
T2 { v: _ } = move_from<T2>(signer::address_of(account))
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

Diagnostics:
error: unnecessary acquires annotation
┌─ tests/acquires-checker/v1-borrow-tests/borrow_global_acquires_extraneous_annotation.move:4:32
4 │ public fun test() acquires T1 {
│ ^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module 0x8675309::A {
struct T1 has key {v: u64}

public fun test() acquires T1 {
}

}

// check: EXTRANEOUS_ACQUIRES_RESOURCE_ANNOTATION_ERROR
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

Diagnostics:
error: unnecessary acquires annotation
┌─ tests/acquires-checker/v1-borrow-tests/borrow_global_acquires_invalid_annotation.move:4:32
4 │ public fun test() acquires T1 {
│ ^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module 0x8675309::A {
struct T1 has key {v: u64}

public fun test() acquires T1 {
test()
}

}

// check: INVALID_ACQUIRES_RESOURCE_ANNOTATION_ERROR
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

Diagnostics:
error: missing acquires annotation for `T1`
┌─ tests/acquires-checker/v1-borrow-tests/borrow_global_acquires_missing_annotation.move:5:16
5 │ public fun test(account: &signer) {
│ ^^^^
6 │ borrow_global_mut<T1>(signer::address_of(account));
│ -------------------------------------------------- acquired here
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module 0x8675309::A {
use std::signer;
struct T1 has key {v: u64}

public fun test(account: &signer) {
borrow_global_mut<T1>(signer::address_of(account));
}

}

// check: MISSING_ACQUIRES_RESOURCE_ANNOTATION_ERROR
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

============ bytecode verification succeeded ========
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module 0x8675309::A {
use std::signer;
struct T1 has key {v: u64}

public fun test1(account: &signer, x: &mut T1) acquires T1 {
// the acquire of t1 does not pollute y
let y = borrow_acquires_t1(account, x);
acquires_t1(account);
move y;
}

fun borrow_acquires_t1(account: &signer, x: &mut T1): &mut u64 acquires T1 {
borrow_global_mut<T1>(signer::address_of(account));
&mut x.v
}

fun acquires_t1(account: &signer) acquires T1 {
T1 { v:_ } = move_from<T1>(signer::address_of(account))
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

Diagnostics:
error: cannot return a reference derived from global `A::T1`
┌─ tests/acquires-checker/v1-borrow-tests/borrow_global_acquires_return_reference_invalid_1.move:10:9
10 │ borrow_global_mut<T1>(signer::address_of(account))
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│ │
│ returned here
│ previous mutable global borrow
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module 0x8675309::A {
use std::signer;
struct T1 has key {v: u64}

public fun test1(account: &signer) acquires T1 {
borrow_acquires_t1(account);
}

fun borrow_acquires_t1(account: &signer): &mut T1 acquires T1 {
borrow_global_mut<T1>(signer::address_of(account))
}
}

// check: RET_UNSAFE_TO_DESTROY_ERROR
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

============ bytecode verification succeeded ========
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module 0x8675309::M {
struct X has copy, drop { f: Y }
struct Y has copy, drop { g: u64, h: u64 }

fun t1() {
let x = X { f: Y { g: 0, h: 0 } };
let g = &mut x.f.g;
let h = &mut x.f.h;

*g = *h;
*h = *g;

foo(g, h);
}

fun foo(_a: &mut u64, _b: &mut u64) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

Diagnostics:
error: missing acquires annotation for `T1`
┌─ tests/acquires-checker/v1-borrow-tests/imm_borrow_global_requires_acquire.move:4:16
4 │ public fun test(addr: address) {
│ ^^^^
5 │ borrow_global<T1>(addr);
│ ----------------------- acquired here
Loading

0 comments on commit 17937e7

Please sign in to comment.