-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move][move-2024] Fix match parsing by adding Match to expression sta…
…rt set (#19342) ## Description Match did not end up in the expression start set due to these features growing separately. Now match parses in more places. This PR also slightly changes parsing error reporting to report what symbol was there in comma list parse failures, allowing for slightly better error reporting(?) ## Test plan New tests added. --- ## 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: - [ ] REST API:
- Loading branch information
Showing
24 changed files
with
117 additions
and
29 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
17 changes: 17 additions & 0 deletions
17
external-crates/move/crates/move-compiler/tests/move_2024/matching/invalid_match_lhs.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,17 @@ | ||
warning[W09002]: unused variable | ||
┌─ tests/move_2024/matching/invalid_match_lhs.move:8:10 | ||
│ | ||
8 │ fun test(z: &mut Maybe<u64>) { | ||
│ ^ Unused parameter 'z'. Consider removing or prefixing with an underscore: '_z' | ||
│ | ||
= This warning can be suppressed with '#[allow(unused_variable)]' applied to the 'module' or module member ('const', 'fun', or 'struct') | ||
|
||
error[E01002]: unexpected token | ||
┌─ tests/move_2024/matching/invalid_match_lhs.move:9:9 | ||
│ | ||
9 │ let { match (z) { Maybe::Just(n) => n, Maybe::Nothing => abort 0 } } = 5; | ||
│ ^ | ||
│ │ | ||
│ Unexpected '{' | ||
│ Expected a variable or struct name | ||
|
12 changes: 12 additions & 0 deletions
12
external-crates/move/crates/move-compiler/tests/move_2024/matching/invalid_match_lhs.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,12 @@ | ||
module 0x42::m; | ||
|
||
public enum Maybe<T> { | ||
Just(T), | ||
Nothing | ||
} | ||
|
||
fun test(z: &mut Maybe<u64>) { | ||
let { match (z) { Maybe::Just(n) => n, Maybe::Nothing => abort 0 } } = 5; | ||
} | ||
|
||
|
51 changes: 51 additions & 0 deletions
51
external-crates/move/crates/move-compiler/tests/move_2024/matching/matching_everywhere.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,51 @@ | ||
module 0x42::m; | ||
|
||
public enum Maybe<T> { | ||
Just(T), | ||
Nothing | ||
} | ||
|
||
|
||
fun helper(_x: u64) { abort 0 } | ||
|
||
fun test(x: &Maybe<u64>, y: Maybe<u64>): u64 { | ||
helper(match (y) { Maybe::Just(n) => n, Maybe::Nothing => 0 }); | ||
|
||
let a: u64 = match (x) { Maybe::Just(n) => *n, Maybe::Nothing => 0 }; | ||
|
||
let b: u64 = loop { | ||
break match (x) { Maybe::Just(n) => *n, Maybe::Nothing => 0 } | ||
}; | ||
|
||
let c: u64 = 'a: { | ||
return 'a match (x) { Maybe::Just(n) => *n, Maybe::Nothing => 0 } | ||
}; | ||
|
||
let d: u64 = 'a: { | ||
while (true) { | ||
return 'a match (x) { Maybe::Just(n) => *n, Maybe::Nothing => 0 } | ||
}; | ||
0 | ||
}; | ||
|
||
while (match (x) { Maybe::Just(_) => true, Maybe::Nothing => false }) { | ||
break | ||
}; | ||
|
||
let e = if (match (x) { Maybe::Just(_) => true, Maybe::Nothing => false, }) return 5 else 0; | ||
|
||
let (f, g) = ( | ||
match (x) { Maybe::Just(n) => *n, Maybe::Nothing => 0 }, | ||
match (x) { Maybe::Just(n) => *n, Maybe::Nothing => 0 } | ||
); | ||
|
||
let h = match (x) { Maybe::Just(n) => *n, Maybe::Nothing => 0 } + 1; | ||
|
||
let i = 1 + match (x) { Maybe::Just(n) => *n, Maybe::Nothing => 0 }; | ||
|
||
let j = match (x) { Maybe::Just(n) => match (x) { Maybe::Just(m) => *n + *m, Maybe::Nothing => 0 }, Maybe::Nothing => 0 }; | ||
|
||
let _q = a + b + c + d + e + f + g + h + i + j; | ||
|
||
return match (x) { Maybe::Just(n) => *n, Maybe::Nothing => 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
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
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
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
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