Skip to content

Commit

Permalink
Fix v1 test input /resources_invalid.move to match v2 test input,
Browse files Browse the repository at this point in the history
and add 2 other variants of the test.
  • Loading branch information
brmataptos committed Sep 17, 2024
1 parent 6b31689 commit 3f3b1d3
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// -- Model dump before bytecode pipeline
module 0x42::objects {
struct ReaderRef {
addr: address,
}
public fun get_addr<T>(ref: &objects::ReaderRef<#0>): address {
select objects::ReaderRef.addr<&objects::ReaderRef<T>>(ref)
}
public inline fun reader<T>(ref: &objects::ReaderRef<#0>): &#0 {
BorrowGlobal(Immutable)<T>(objects::get_addr<T>(ref))
}
} // end 0x42::objects
module 0x42::token {
use 0x42::objects as obj; // resolved as: 0x42::objects
struct Token {
val: u64,
}
public fun get_value(ref: &objects::ReaderRef<token::Token>): u64
acquires token::Token(*)
{
select token::Token.val<&token::Token>({
let (ref: &objects::ReaderRef<token::Token>): (&objects::ReaderRef<token::Token>) = Tuple(ref);
BorrowGlobal(Immutable)<token::Token>(objects::get_addr<token::Token>(ref))
})
}
} // end 0x42::token


============ bytecode verification succeeded ========
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module 0x42::objects {

struct ReaderRef<phantom T: key> has store {
addr: address
}

public fun get_addr<T: key>(ref: &ReaderRef<T>): address {
ref.addr
}

public inline fun reader<T: key>(ref: &ReaderRef<T>): &T {
borrow_global<T>(get_addr(ref))
}
}

module 0x42::token {
use 0x42::objects as obj;

struct Token has key { val: u64 }

public fun get_value(ref: &obj::ReaderRef<Token>): u64 acquires Token {
obj::reader(ref).val
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

Diagnostics:
error: missing acquires annotation for `Token`
┌─ tests/checking/inlining/resources_valid_noacquires.move:21:16
12 │ borrow_global<T>(get_addr(ref))
│ ------------------------------- acquired here
·
21 │ public fun get_value(ref: &obj::ReaderRef<Token>): u64 {
│ ^^^^^^^^^
22 │ obj::reader(ref).val
│ ---------------- from a call inlined at this callsite
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module 0x42::objects {

struct ReaderRef<phantom T: key> has store {
addr: address
}

public fun get_addr<T: key>(ref: &ReaderRef<T>): address {
ref.addr
}

public inline fun reader<T: key>(ref: &ReaderRef<T>): &T {
borrow_global<T>(get_addr(ref))
}
}

module 0x42::token {
use 0x42::objects as obj;

struct Token has key { val: u64 }

public fun get_value(ref: &obj::ReaderRef<Token>): u64 {
obj::reader(ref).val
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
error[E04020]: missing acquires annotation
┌─ tests/move_check/inlining/resources_invalid.move:8:9
8 │ borrow_global<T>(ref.addr)
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^ The call acquires '0x42::token::Token', but the 'acquires' list for the current function 'get_value` does not contain this type. It must be present in the calling context's acquires list

error[E14002]: Inlined code invalid in this context
┌─ tests/move_check/inlining/resources_invalid.move:8:26
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module 0x42::token {

struct Token has key { val: u64 }

public fun get_value(ref: &obj::ReaderRef<Token>): u64 {
public fun get_value(ref: &obj::ReaderRef<Token>): u64 acquires Token {
obj::reader(ref).val
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module 0x42::objects {

struct ReaderRef<phantom T: key> has store {
addr: address
}

public fun get_addr<T: key>(ref: &ReaderRef<T>): address {
ref.addr
}

public inline fun reader<T: key>(ref: &ReaderRef<T>): &T {
borrow_global<T>(get_addr(ref))
}
}

module 0x42::token {
use 0x42::objects as obj;

struct Token has key { val: u64 }

public fun get_value(ref: &obj::ReaderRef<Token>): u64 acquires Token {
obj::reader(ref).val
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
error[E04020]: missing acquires annotation
┌─ tests/move_check/inlining/resources_valid_noacquires.move:12:9
12 │ borrow_global<T>(get_addr(ref))
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The call acquires '0x42::token::Token', but the 'acquires' list for the current function 'get_value` does not contain this type. It must be present in the calling context's acquires list

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module 0x42::objects {

struct ReaderRef<phantom T: key> has store {
addr: address
}

public fun get_addr<T: key>(ref: &ReaderRef<T>): address {
ref.addr
}

public inline fun reader<T: key>(ref: &ReaderRef<T>): &T {
borrow_global<T>(get_addr(ref))
}
}

module 0x42::token {
use 0x42::objects as obj;

struct Token has key { val: u64 }

public fun get_value(ref: &obj::ReaderRef<Token>): u64 {
obj::reader(ref).val
}
}

0 comments on commit 3f3b1d3

Please sign in to comment.