-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move] Fix issue where varcalls could persist into typing without an …
…error. (#17958) ## Description This fixes a bug in how var calls were being resolved across naming into typing, when the variable was not a valid macro call target. This also adds a `lambda` feature gate to make error reporting a bit nicer in these cases. ## Test plan New tests cover the crash/bug and ensure it doesn't occur now. --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK:
- Loading branch information
Showing
19 changed files
with
207 additions
and
6 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
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
21 changes: 21 additions & 0 deletions
21
...rnal-crates/move/crates/move-compiler/tests/move_2024/naming/macro_var_as_fun_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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E03004]: unbound type | ||
┌─ tests/move_2024/naming/macro_var_as_fun_invalid.move:3:13 | ||
│ | ||
3 │ let $var = 0; | ||
│ ^^^^ Unbound type '$var' in current scope | ||
|
||
error[E01002]: unexpected token | ||
┌─ tests/move_2024/naming/macro_var_as_fun_invalid.move:3:18 | ||
│ | ||
3 │ let $var = 0; | ||
│ ^ | ||
│ │ | ||
│ Unexpected '=' | ||
│ Expected '{' | ||
|
||
error[E03005]: unbound unscoped name | ||
┌─ tests/move_2024/naming/macro_var_as_fun_invalid.move:4:9 | ||
│ | ||
4 │ $var(); | ||
│ ^^^^ Unbound function '$var' in current scope | ||
|
6 changes: 6 additions & 0 deletions
6
...nal-crates/move/crates/move-compiler/tests/move_2024/naming/macro_var_as_fun_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module a::test_panic { | ||
public fun test_panic() { | ||
let $var = 0; | ||
$var(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
external-crates/move/crates/move-compiler/tests/move_2024/naming/var_as_fun_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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error[E04029]: invalid function call | ||
┌─ tests/move_2024/naming/var_as_fun_invalid.move:4:9 | ||
│ | ||
4 │ var(); | ||
│ ^^^ Unexpected invocation of parameter or local 'var'. Non-syntax variables cannot be invoked as functions | ||
│ | ||
= Only macro syntax variables, e.g. '$var', may be invoked as functions. | ||
|
6 changes: 6 additions & 0 deletions
6
external-crates/move/crates/move-compiler/tests/move_2024/naming/var_as_fun_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module a::test_panic { | ||
public fun test_panic() { | ||
let var = 0; | ||
var(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
external-crates/move/crates/move-compiler/tests/move_2024/naming/var_as_fun_macro.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,9 @@ | ||
error[E04032]: unable to expand macro function | ||
┌─ tests/move_2024/naming/var_as_fun_macro.move:3:9 | ||
│ | ||
3 │ $var(); | ||
│ ^^^^^^ Cannot call non-lambda argument | ||
· | ||
8 │ test_panic!(0) | ||
│ - Expected a lambda argument | ||
|
10 changes: 10 additions & 0 deletions
10
external-crates/move/crates/move-compiler/tests/move_2024/naming/var_as_fun_macro.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,10 @@ | ||
module a::test_panic { | ||
public macro fun test_panic($var: u64): u64 { | ||
$var(); | ||
0 | ||
} | ||
|
||
public fun t(): u64 { | ||
test_panic!(0) | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
...s/move/crates/move-compiler/tests/move_check/feature_gate/macro_definition_with_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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
error[E13001]: feature is not supported in specified edition | ||
┌─ tests/move_check/feature_gate/macro_definition_with_usage.move:2:12 | ||
│ | ||
2 │ public macro fun do($f: || ()) { $f() } | ||
│ ^^^^^ 'macro' functions are not supported by current edition 'legacy', only '2024.alpha' and '2024.beta' support this feature | ||
│ | ||
= You can update the edition in the 'Move.toml', or via command line flag if invoking the compiler directly. | ||
|
||
error[E13001]: feature is not supported in specified edition | ||
┌─ tests/move_check/feature_gate/macro_definition_with_usage.move:2:38 | ||
│ | ||
2 │ public macro fun do($f: || ()) { $f() } | ||
│ ^^^^ lambda expressions are not supported by current edition 'legacy', only '2024.alpha' and '2024.beta' support this feature | ||
│ | ||
= You can update the edition in the 'Move.toml', or via command line flag if invoking the compiler directly. | ||
|
||
error[E13001]: feature is not supported in specified edition | ||
┌─ tests/move_check/feature_gate/macro_definition_with_usage.move:4:24 | ||
│ | ||
4 │ public fun t() { do!(|| q() ) } | ||
│ ^ 'macro' functions are not supported by current edition 'legacy', only '2024.alpha' and '2024.beta' support this feature | ||
│ | ||
= You can update the edition in the 'Move.toml', or via command line flag if invoking the compiler directly. | ||
|
5 changes: 5 additions & 0 deletions
5
.../move/crates/move-compiler/tests/move_check/feature_gate/macro_definition_with_usage.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,5 @@ | ||
module a::m { | ||
public macro fun do($f: || ()) { $f() } | ||
public fun q() { } | ||
public fun t() { do!(|| q() ) } | ||
} |
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
16 changes: 16 additions & 0 deletions
16
external-crates/move/crates/move-compiler/tests/move_check/naming/var_as_fun_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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
error[E04029]: invalid function call | ||
┌─ tests/move_check/naming/var_as_fun_invalid.move:4:9 | ||
│ | ||
4 │ var(); | ||
│ ^^^ Unexpected invocation of parameter or local 'var'. Non-syntax variables cannot be invoked as functions | ||
│ | ||
= Only macro syntax variables, e.g. '$var', may be invoked as functions. | ||
|
||
error[E13001]: feature is not supported in specified edition | ||
┌─ tests/move_check/naming/var_as_fun_invalid.move:4:9 | ||
│ | ||
4 │ var(); | ||
│ ^^^^^ lambda expressions are not supported by current edition 'legacy', only '2024.alpha' and '2024.beta' support this feature | ||
│ | ||
= You can update the edition in the 'Move.toml', or via command line flag if invoking the compiler directly. | ||
|
6 changes: 6 additions & 0 deletions
6
external-crates/move/crates/move-compiler/tests/move_check/naming/var_as_fun_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module a::test_panic { | ||
public fun test_panic() { | ||
let var = 0; | ||
var(); | ||
} | ||
} |
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