-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move-2024][easy] Disallow macro variables to be used as exp dotted b…
…ase expressions (#16313) ## Description What it says on the tin -- this is just to reduce programmer confusion ## Test Plan New test case plus updated expectations --- If your changes are not user-facing and do not break anything, you can skip the following section. Otherwise, please briefly describe what has changed under the Release Notes section. ### Type of Change (Check all that apply) - [ ] protocol change - [ ] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes
- Loading branch information
Showing
20 changed files
with
161 additions
and
63 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
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
20 changes: 14 additions & 6 deletions
20
...ove/crates/move-compiler/tests/move_2024/typing/macro_arg_by_name_invalid_usage_value.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,12 +1,20 @@ | ||
error[E04026]: invalid 'copy' usage | ||
┌─ tests/move_2024/typing/macro_arg_by_name_invalid_usage_value.move:4:9 | ||
error[E03006]: unexpected name in this position | ||
┌─ tests/move_2024/typing/macro_arg_by_name_invalid_usage_value.move:4:14 | ||
│ | ||
4 │ copy $x; | ||
│ ^^^^ Invalid 'copy'. Expected a variable or path. | ||
│ ^^ Macro parameters are not allowed to appear in paths | ||
│ | ||
= To use a macro parameter as a value in a path expression, first bind it to a local variable, e.g. 'let x = $x;' | ||
= Macro parameters are always treated as value expressions, and are not modified by path operations. | ||
Path operations include 'move', 'copy', '&', '&mut', and field references | ||
|
||
error[E04027]: invalid 'move' usage | ||
┌─ tests/move_2024/typing/macro_arg_by_name_invalid_usage_value.move:5:9 | ||
error[E03006]: unexpected name in this position | ||
┌─ tests/move_2024/typing/macro_arg_by_name_invalid_usage_value.move:5:14 | ||
│ | ||
5 │ move $x; | ||
│ ^^^^ Invalid 'move'. Expected a variable or path. | ||
│ ^^ Macro parameters are not allowed to appear in paths | ||
│ | ||
= To use a macro parameter as a value in a path expression, first bind it to a local variable, e.g. 'let x = $x;' | ||
= Macro parameters are always treated as value expressions, and are not modified by path operations. | ||
Path operations include 'move', 'copy', '&', '&mut', and field references | ||
|
3 changes: 2 additions & 1 deletion
3
...ve/crates/move-compiler/tests/move_2024/typing/macro_arg_by_name_invalid_usage_value.move
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
20 changes: 14 additions & 6 deletions
20
.../move/crates/move-compiler/tests/move_2024/typing/macro_arg_by_name_invalid_usage_var.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,12 +1,20 @@ | ||
error[E04026]: invalid 'copy' usage | ||
┌─ tests/move_2024/typing/macro_arg_by_name_invalid_usage_var.move:4:9 | ||
error[E03006]: unexpected name in this position | ||
┌─ tests/move_2024/typing/macro_arg_by_name_invalid_usage_var.move:4:14 | ||
│ | ||
4 │ copy $x; | ||
│ ^^^^ Invalid 'copy'. Expected a variable or path. | ||
│ ^^ Macro parameters are not allowed to appear in paths | ||
│ | ||
= To use a macro parameter as a value in a path expression, first bind it to a local variable, e.g. 'let x = $x;' | ||
= Macro parameters are always treated as value expressions, and are not modified by path operations. | ||
Path operations include 'move', 'copy', '&', '&mut', and field references | ||
|
||
error[E04027]: invalid 'move' usage | ||
┌─ tests/move_2024/typing/macro_arg_by_name_invalid_usage_var.move:5:9 | ||
error[E03006]: unexpected name in this position | ||
┌─ tests/move_2024/typing/macro_arg_by_name_invalid_usage_var.move:5:14 | ||
│ | ||
5 │ move $x; | ||
│ ^^^^ Invalid 'move'. Expected a variable or path. | ||
│ ^^ Macro parameters are not allowed to appear in paths | ||
│ | ||
= To use a macro parameter as a value in a path expression, first bind it to a local variable, e.g. 'let x = $x;' | ||
= Macro parameters are always treated as value expressions, and are not modified by path operations. | ||
Path operations include 'move', 'copy', '&', '&mut', and field references | ||
|
3 changes: 2 additions & 1 deletion
3
...move/crates/move-compiler/tests/move_2024/typing/macro_arg_by_name_invalid_usage_var.move
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
14 changes: 2 additions & 12 deletions
14
...ates/move/crates/move-compiler/tests/move_2024/typing/macro_arg_by_name_strange_usage.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,21 +1,11 @@ | ||
error[E06002]: use of unassigned variable | ||
┌─ tests/move_2024/typing/macro_arg_by_name_strange_usage.move:14:14 | ||
│ | ||
14 │ foo!(x); // TODO improve this error message | ||
│ ^ | ||
│ │ | ||
│ Invalid usage of previously moved variable 'x'. | ||
│ Suggestion: use 'copy x' to avoid the move. | ||
│ In a loop, this typically means it was moved in the first iteration, and is not available by the second iteration. | ||
|
||
error[E05001]: ability constraint not satisfied | ||
┌─ tests/move_2024/typing/macro_arg_by_name_strange_usage.move:17:14 | ||
┌─ tests/move_2024/typing/macro_arg_by_name_strange_usage.move:18:14 | ||
│ | ||
2 │ public struct X() has drop; | ||
│ - To satisfy the constraint, the 'copy' ability would need to be added here | ||
3 │ public struct S { f: X } has drop; | ||
│ - The type 'a::m::X' does not have the ability 'copy' | ||
· | ||
17 │ foo!(s.f); // TODO improve this error message | ||
18 │ foo!(s.f); // TODO improve this error message | ||
│ ^^^ Invalid implicit copy of field 'f' without the 'copy' ability | ||
|
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
10 changes: 0 additions & 10 deletions
10
...ve/crates/move-compiler/tests/move_2024/typing/macro_arg_by_name_strange_usage_fields.exp
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
10 changes: 5 additions & 5 deletions
10
...tes/move/crates/move-compiler/tests/move_2024/typing/macro_duck_typing_method_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,9 +1,9 @@ | ||
error[E04023]: invalid method call | ||
┌─ tests/move_2024/typing/macro_duck_typing_method_invalid.move:4:9 | ||
┌─ tests/move_2024/typing/macro_duck_typing_method_invalid.move:5:9 | ||
│ | ||
4 │ $x.foo() | ||
│ ^^^^^^^^ | ||
│ │ │ | ||
│ │ No local 'use fun' alias was found for 'a::m::X.foo', and no function 'foo' was found in the defining module 'a::m' | ||
5 │ x.foo() | ||
│ ^^^^^^^ | ||
│ │ │ | ||
│ │ No local 'use fun' alias was found for 'a::m::X.foo', and no function 'foo' was found in the defining module 'a::m' | ||
│ Invalid method call. No known method 'foo' on type 'a::m::X' | ||
|
3 changes: 2 additions & 1 deletion
3
...es/move/crates/move-compiler/tests/move_2024/typing/macro_duck_typing_method_invalid.move
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
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
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
50 changes: 50 additions & 0 deletions
50
external-crates/move/crates/move-compiler/tests/move_2024/typing/macros_dont_allow_paths.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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
error[E03006]: unexpected name in this position | ||
┌─ tests/move_2024/typing/macros_dont_allow_paths.move:6:18 | ||
│ | ||
6 │ let _m = $s.x; // disallowed | ||
│ ^^ Macro parameters are not allowed to appear in paths | ||
│ | ||
= To use a macro parameter as a value in a path expression, first bind it to a local variable, e.g. 'let s = $s;' | ||
= Macro parameters are always treated as value expressions, and are not modified by path operations. | ||
Path operations include 'move', 'copy', '&', '&mut', and field references | ||
|
||
error[E03006]: unexpected name in this position | ||
┌─ tests/move_2024/typing/macros_dont_allow_paths.move:7:24 | ||
│ | ||
7 │ let _vs = &mut $y; // disallowed | ||
│ ^^ Macro parameters are not allowed to appear in paths | ||
│ | ||
= To use a macro parameter as a value in a path expression, first bind it to a local variable, e.g. 'let y = $y;' | ||
= Macro parameters are always treated as value expressions, and are not modified by path operations. | ||
Path operations include 'move', 'copy', '&', '&mut', and field references | ||
|
||
error[E03006]: unexpected name in this position | ||
┌─ tests/move_2024/typing/macros_dont_allow_paths.move:8:19 | ||
│ | ||
8 │ let _q = &$n; // disallowed | ||
│ ^^ Macro parameters are not allowed to appear in paths | ||
│ | ||
= To use a macro parameter as a value in a path expression, first bind it to a local variable, e.g. 'let n = $n;' | ||
= Macro parameters are always treated as value expressions, and are not modified by path operations. | ||
Path operations include 'move', 'copy', '&', '&mut', and field references | ||
|
||
error[E03006]: unexpected name in this position | ||
┌─ tests/move_2024/typing/macros_dont_allow_paths.move:9:23 | ||
│ | ||
9 │ let _q = copy $n; // disallowed | ||
│ ^^ Macro parameters are not allowed to appear in paths | ||
│ | ||
= To use a macro parameter as a value in a path expression, first bind it to a local variable, e.g. 'let n = $n;' | ||
= Macro parameters are always treated as value expressions, and are not modified by path operations. | ||
Path operations include 'move', 'copy', '&', '&mut', and field references | ||
|
||
error[E03006]: unexpected name in this position | ||
┌─ tests/move_2024/typing/macros_dont_allow_paths.move:10:23 | ||
│ | ||
10 │ let _q = move $n; // disallowed | ||
│ ^^ Macro parameters are not allowed to appear in paths | ||
│ | ||
= To use a macro parameter as a value in a path expression, first bind it to a local variable, e.g. 'let n = $n;' | ||
= Macro parameters are always treated as value expressions, and are not modified by path operations. | ||
Path operations include 'move', 'copy', '&', '&mut', and field references | ||
|
20 changes: 20 additions & 0 deletions
20
...rnal-crates/move/crates/move-compiler/tests/move_2024/typing/macros_dont_allow_paths.move
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module 0x42::m { | ||
|
||
public struct S has drop { x: u64 } | ||
|
||
macro fun bad_paths($s: S, $y: vector<u64>, $n: u64): (S, vector<u64>, u64) { | ||
let _m = $s.x; // disallowed | ||
let _vs = &mut $y; // disallowed | ||
let _q = &$n; // disallowed | ||
let _q = copy $n; // disallowed | ||
let _q = move $n; // disallowed | ||
($s, $y, $n) | ||
} | ||
|
||
fun call_macro() { | ||
let s = S { x: 10 }; | ||
let n = 0; | ||
let vs = vector[]; | ||
let (_, _, _) = bad_paths!(s, vs, n); | ||
} | ||
} |