-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Compiler-v2] check access for structs #12821
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,7 +333,8 @@ const TEST_CONFIGS: Lazy<BTreeMap<&str, TestConfig>> = Lazy::new(|| { | |
include: vec!["/acquires-checker/"], | ||
exclude: vec![], | ||
exp_suffix: None, | ||
options: opts.clone(), | ||
// Skip access check to avoid error message change in the acquires-checker | ||
options: opts.clone().set_experiment(Experiment::ACCESS_CHECK, false), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. skip access check for acquires-checker so that the error messages remain the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add this as a comment please? |
||
// Run the full compiler pipeline to double-check the result. | ||
stop_after: StopAfter::FileFormat, | ||
dump_ast: DumpLevel::None, | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add more inline tests, specifically, inline functions that do each of the restricted cases? We may then want to improve error messages for the inlined cases (like is done for visibility of calls).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done