-
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.
[Compiler-v2] check access for structs (#12821)
* check field * handle comments
- Loading branch information
1 parent
be0ef97
commit 59586fe
Showing
26 changed files
with
690 additions
and
159 deletions.
There are no files selected for viewing
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
12 changes: 6 additions & 6 deletions
12
...checking-lang-v1/invalid_type_acquire.exp → ...ang-v1/v1-typing/invalid_type_acquire.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
File renamed without changes.
28 changes: 6 additions & 22 deletions
28
third_party/move/move-compiler-v2/tests/checking/inlining/resources_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 |
---|---|---|
@@ -1,28 +1,12 @@ | ||
// -- Model dump before bytecode pipeline | ||
module 0x42::objects { | ||
struct ReaderRef { | ||
addr: address, | ||
} | ||
} // 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>(select objects::ReaderRef.addr<&objects::ReaderRef<token::Token>>(ref)) | ||
}) | ||
} | ||
} // end 0x42::token | ||
|
||
|
||
Diagnostics: | ||
bug: struct not defined | ||
error: Invalid operation: access of the field `addr` on type `objects::ReaderRef` can only be done within the defining module `0x42::objects` | ||
┌─ tests/checking/inlining/resources_invalid.move:17:16 | ||
│ | ||
8 │ borrow_global<T>(ref.addr) | ||
│ -------- accessed here | ||
· | ||
17 │ public fun get_value(ref: &obj::ReaderRef<Token>): u64 acquires Token { | ||
│ ^^^^^^^^^ | ||
18 │ obj::reader(ref).val | ||
│ ---------------- from a call inlined at this callsite |
38 changes: 18 additions & 20 deletions
38
third_party/move/move-compiler-v2/tests/checking/typing/borrow_field_internal.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 |
---|---|---|
@@ -1,20 +1,18 @@ | ||
// -- Model dump before bytecode pipeline | ||
module 0x2::X { | ||
struct S { | ||
f: u64, | ||
} | ||
public fun s(): X::S { | ||
pack X::S(0) | ||
} | ||
} // end 0x2::X | ||
module 0x2::M { | ||
use 0x2::X; // resolved as: 0x2::X | ||
private fun t0() { | ||
Borrow(Immutable)(select X::S.f<X::S>(X::s())); | ||
{ | ||
let s: &X::S = Borrow(Immutable)(X::s()); | ||
Borrow(Immutable)(select X::S.f<&X::S>(s)); | ||
Abort(0) | ||
} | ||
} | ||
} // end 0x2::M | ||
|
||
Diagnostics: | ||
error: Invalid operation: access of the field `f` on type `X::S` can only be done within the defining module `0x2::X` | ||
┌─ tests/checking/typing/borrow_field_internal.move:12:9 | ||
│ | ||
12 │ fun t0() { | ||
│ ^^ | ||
13 │ (&X::s().f: &u64); | ||
│ -------- accessed here | ||
|
||
error: Invalid operation: access of the field `f` on type `X::S` can only be done within the defining module `0x2::X` | ||
┌─ tests/checking/typing/borrow_field_internal.move:12:9 | ||
│ | ||
12 │ fun t0() { | ||
│ ^^ | ||
· | ||
15 │ (&s.f: &u64); | ||
│ --- accessed here |
39 changes: 19 additions & 20 deletions
39
third_party/move/move-compiler-v2/tests/checking/typing/global_builtins_script.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 |
---|---|---|
@@ -1,20 +1,19 @@ | ||
// -- Model dump before bytecode pipeline | ||
module 0x42::M { | ||
struct R { | ||
dummy_field: bool, | ||
} | ||
public fun new(): M::R { | ||
pack M::R(false) | ||
} | ||
} // end 0x42::M | ||
module <SELF>_0 { | ||
use 0x42::M; // resolved as: 0x42::M | ||
private fun test<Token>(account: signer) { | ||
{ | ||
let r: M::R = M::new(); | ||
BorrowGlobal(Immutable)<M::R>(0x1); | ||
MoveTo<M::R>(Borrow(Immutable)(account), r); | ||
Tuple() | ||
} | ||
} | ||
} // end <SELF>_0 | ||
|
||
Diagnostics: | ||
error: Invalid operation: storage operation on type `M::R` can only be done within the defining module `0x42::M` | ||
┌─ tests/checking/typing/global_builtins_script.move:14:5 | ||
│ | ||
14 │ fun test<Token>(account: signer) { | ||
│ ^^^^ | ||
15 │ let r = M::new(); | ||
16 │ borrow_global<M::R>(@0x1); | ||
│ ------------------------- called here | ||
|
||
error: Invalid operation: storage operation on type `M::R` can only be done within the defining module `0x42::M` | ||
┌─ tests/checking/typing/global_builtins_script.move:14:5 | ||
│ | ||
14 │ fun test<Token>(account: signer) { | ||
│ ^^^^ | ||
· | ||
17 │ move_to(&account, r); | ||
│ -------------------- called here |
38 changes: 18 additions & 20 deletions
38
...arty/move/move-compiler-v2/tests/checking/typing/implicit_deref_borrow_field_internal.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 |
---|---|---|
@@ -1,20 +1,18 @@ | ||
// -- Model dump before bytecode pipeline | ||
module 0x2::X { | ||
struct S { | ||
f: u64, | ||
} | ||
public fun s(): X::S { | ||
pack X::S(0) | ||
} | ||
} // end 0x2::X | ||
module 0x2::M { | ||
use 0x2::X; // resolved as: 0x2::X | ||
private fun t0() { | ||
select X::S.f<X::S>(X::s()); | ||
{ | ||
let s: &X::S = Borrow(Immutable)(X::s()); | ||
select X::S.f<&X::S>(s); | ||
Abort(0) | ||
} | ||
} | ||
} // end 0x2::M | ||
|
||
Diagnostics: | ||
error: Invalid operation: access of the field `f` on type `X::S` can only be done within the defining module `0x2::X` | ||
┌─ tests/checking/typing/implicit_deref_borrow_field_internal.move:12:9 | ||
│ | ||
12 │ fun t0() { | ||
│ ^^ | ||
13 │ (X::s().f: u64); | ||
│ -------- accessed here | ||
|
||
error: Invalid operation: access of the field `f` on type `X::S` can only be done within the defining module `0x2::X` | ||
┌─ tests/checking/typing/implicit_deref_borrow_field_internal.move:12:9 | ||
│ | ||
12 │ fun t0() { | ||
│ ^^ | ||
· | ||
15 │ (s.f: u64); | ||
│ --- accessed here |
38 changes: 18 additions & 20 deletions
38
third_party/move/move-compiler-v2/tests/checking/typing/mutate_field_internal.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 |
---|---|---|
@@ -1,20 +1,18 @@ | ||
// -- Model dump before bytecode pipeline | ||
module 0x2::X { | ||
struct S { | ||
f: u64, | ||
} | ||
public fun s(): X::S { | ||
pack X::S(0) | ||
} | ||
} // end 0x2::X | ||
module 0x2::M { | ||
use 0x2::X; // resolved as: 0x2::X | ||
private fun t0() { | ||
select X::S.f<X::S>(X::s()) = 0; | ||
{ | ||
let s: &mut X::S = Borrow(Mutable)(X::s()); | ||
select X::S.f<&mut X::S>(s) = 0; | ||
Abort(0) | ||
} | ||
} | ||
} // end 0x2::M | ||
|
||
Diagnostics: | ||
error: Invalid operation: access of the field `f` on type `X::S` can only be done within the defining module `0x2::X` | ||
┌─ tests/checking/typing/mutate_field_internal.move:12:9 | ||
│ | ||
12 │ fun t0() { | ||
│ ^^ | ||
13 │ X::s().f = 0; | ||
│ -------- accessed here | ||
|
||
error: Invalid operation: access of the field `f` on type `X::S` can only be done within the defining module `0x2::X` | ||
┌─ tests/checking/typing/mutate_field_internal.move:12:9 | ||
│ | ||
12 │ fun t0() { | ||
│ ^^ | ||
· | ||
15 │ s.f = 0; | ||
│ --- accessed here |
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
Oops, something went wrong.