-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Compiler-v2] Check recursive definition for constants (#14741)
* check recursive in constant definition * add tests * add tests for duplicated constants * fix
- Loading branch information
1 parent
52cd461
commit 63de0c5
Showing
14 changed files
with
259 additions
and
25 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
third_party/move/move-compiler-v2/tests/checking-lang-v1/v1-typing/refer_other_constants.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,7 @@ | ||
|
||
Diagnostics: | ||
error: not supported before language version `2.0`: constant definitions referring to other constants | ||
┌─ tests/checking-lang-v1/v1-typing/refer_other_constants.move:3:5 | ||
│ | ||
3 │ const X: u64 = Y; | ||
│ ^^^^^^^^^^^^^^^^^ |
14 changes: 14 additions & 0 deletions
14
...d_party/move/move-compiler-v2/tests/checking-lang-v1/v1-typing/refer_other_constants.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,14 @@ | ||
address 0x42 { | ||
module M { | ||
const X: u64 = Y; | ||
const Y: u64 = 0; | ||
|
||
public fun get_x(): u64 { | ||
X | ||
} | ||
|
||
public fun get_y(): u64 { | ||
Y | ||
} | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
third_party/move/move-compiler-v2/tests/checking/typing/constant_duplicate.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 @@ | ||
|
||
Diagnostics: | ||
error: duplicate declaration, item, or annotation | ||
┌─ tests/checking/typing/constant_duplicate.move:3:11 | ||
│ | ||
2 │ const LN2_X_32: u64 = 32 * 2977044472; | ||
│ -------- Alias previously defined here | ||
3 │ const LN2_X_32: u64 = 32 * 2977044472; | ||
│ ^^^^^^^^ Duplicate module member or alias 'LN2_X_32'. Top level names in a namespace must be unique |
4 changes: 4 additions & 0 deletions
4
third_party/move/move-compiler-v2/tests/checking/typing/constant_duplicate.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,4 @@ | ||
module 0x42::constant_duplicate { | ||
const LN2_X_32: u64 = 32 * 2977044472; | ||
const LN2_X_32: u64 = 32 * 2977044472; | ||
} |
60 changes: 51 additions & 9 deletions
60
third_party/move/move-compiler-v2/tests/checking/typing/recursive_constant.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,51 @@ | ||
// -- Model dump before bytecode pipeline | ||
module 0x42::M { | ||
public fun get_x(): u64 { | ||
false | ||
} | ||
public fun get_y(): u64 { | ||
false | ||
} | ||
} // end 0x42::M | ||
|
||
Diagnostics: | ||
error: Found recursive definition of a constant `X`; cycle formed by definitions below | ||
┌─ tests/checking/typing/recursive_constant.move:3:5 | ||
│ | ||
3 │ const X: u64 = Y; | ||
│ ^^^^^^^^^^^^^^^^^ | ||
│ │ | ||
│ `X` is defined here | ||
4 │ const Y: u64 = X; | ||
│ ----------------- `Y` is defined here | ||
|
||
error: Found recursive definition of a constant `F`; cycle formed by definitions below | ||
┌─ tests/checking/typing/recursive_constant.move:6:5 | ||
│ | ||
6 │ const F: u64 = F; | ||
│ ^^^^^^^^^^^^^^^^^ | ||
│ │ | ||
│ `F` is defined here | ||
|
||
error: Invalid expression in `const`. Constant folding failed due to incomplete evaluation | ||
┌─ tests/checking/typing/recursive_constant.move:8:8 | ||
│ | ||
8 │ Z + A | ||
│ ^^^^^ | ||
|
||
error: Invalid expression in `const`. Constant folding failed due to incomplete evaluation | ||
┌─ tests/checking/typing/recursive_constant.move:10:20 | ||
│ | ||
10 │ const A: u64 = B + C; | ||
│ ^^^^^ | ||
|
||
error: Found recursive definition of a constant `A`; cycle formed by definitions below | ||
┌─ tests/checking/typing/recursive_constant.move:10:5 | ||
│ | ||
7 │ ╭ const X1: u64 = { | ||
8 │ │ Z + A | ||
9 │ │ }; | ||
│ ╰──────' `X1` is defined here | ||
10 │ const A: u64 = B + C; | ||
│ ^^^^^^^^^^^^^^^^^^^^^ | ||
│ │ | ||
│ `A` is defined here | ||
11 │ const B: u64 = X1; | ||
│ ------------------ `B` is defined here | ||
|
||
error: Invalid expression in `const`. Constant folding failed due to incomplete evaluation | ||
┌─ tests/checking/typing/recursive_constant.move:12:20 | ||
│ | ||
12 │ const C: u64 = Z + B; | ||
│ ^^^^^ |
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
8 changes: 8 additions & 0 deletions
8
third_party/move/move-compiler/tests/move_check/typing/constant_duplicate.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[E02001]: duplicate declaration, item, or annotation | ||
┌─ tests/move_check/typing/constant_duplicate.move:3:11 | ||
│ | ||
2 │ const LN2_X_32: u64 = 32 * 2977044472; | ||
│ -------- Alias previously defined here | ||
3 │ const LN2_X_32: u64 = 32 * 2977044472; | ||
│ ^^^^^^^^ Duplicate module member or alias 'LN2_X_32'. Top level names in a namespace must be unique | ||
|
4 changes: 4 additions & 0 deletions
4
third_party/move/move-compiler/tests/move_check/typing/constant_duplicate.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,4 @@ | ||
module 0x42::constant_duplicate { | ||
const LN2_X_32: u64 = 32 * 2977044472; | ||
const LN2_X_32: u64 = 32 * 2977044472; | ||
} |
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