forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
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][enums] Fix a small issue when match is malformed (M…
…ystenLabs#18387) ## Description This fixes a bug that was previously a compiler crash when a match was malformed and counterexample generation occurred. This was due to some changes for parser resilience combined with moving match analysis to typing. ## Test plan Added the repro test, and it now produces the error as expected. --- ## 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
7 changed files
with
84 additions
and
16 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
6 changes: 6 additions & 0 deletions
6
...tes/move/crates/move-compiler/tests/move_2024/matching/counterexample_malformed_match.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,6 @@ | ||
error[E04016]: too few arguments | ||
┌─ tests/move_2024/matching/counterexample_malformed_match.move:18:9 | ||
│ | ||
18 │ SomeEnum::PositionalFields(_, ) => (), | ||
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Missing pattern for field '1' in 'a::m::SomeEnum::PositionalFields' | ||
|
20 changes: 20 additions & 0 deletions
20
...es/move/crates/move-compiler/tests/move_2024/matching/counterexample_malformed_match.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 a::m; | ||
|
||
public struct SomeStruct has drop { | ||
some_field: u64, | ||
} | ||
|
||
public enum SomeEnum has drop { | ||
PositionalFields(u64, SomeStruct), | ||
} | ||
|
||
public fun match_variant(s: SomeStruct) { | ||
use a::m::SomeEnum as SE; | ||
let e = SE::PositionalFields(42, s); | ||
match (e) { | ||
SomeEnum::PositionalFields(num, s) => { | ||
num + s.some_field; | ||
}, | ||
SomeEnum::PositionalFields(_, ) => (), | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...s/move/crates/move-compiler/tests/move_2024/matching/counterexample_malformed_match_2.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,6 @@ | ||
error[E03010]: unbound field | ||
┌─ tests/move_2024/matching/counterexample_malformed_match_2.move:18:9 | ||
│ | ||
18 │ SomeEnum::PositionalFields(_, _, _) => (), | ||
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Unbound field '2' in 'a::m::SomeEnum::PositionalFields' | ||
|
20 changes: 20 additions & 0 deletions
20
.../move/crates/move-compiler/tests/move_2024/matching/counterexample_malformed_match_2.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 a::m; | ||
|
||
public struct SomeStruct has drop { | ||
some_field: u64, | ||
} | ||
|
||
public enum SomeEnum has drop { | ||
PositionalFields(u64, SomeStruct), | ||
} | ||
|
||
public fun match_variant(s: SomeStruct) { | ||
use a::m::SomeEnum as SE; | ||
let e = SE::PositionalFields(42, s); | ||
match (e) { | ||
SomeEnum::PositionalFields(num, s) => { | ||
num + s.some_field; | ||
}, | ||
SomeEnum::PositionalFields(_, _, _) => (), | ||
} | ||
} |