-
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.
treat _ as a wildcard, not a var, in function parameter in Move Lang …
…V2+ (#14962) In Move Language 2.0+, treat a function parameter named "_" as a wildcard value-sink, not a variable. Fixes #14949.
- Loading branch information
1 parent
78b3331
commit 9bc37be
Showing
22 changed files
with
1,852 additions
and
13 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
37 changes: 37 additions & 0 deletions
37
third_party/move/move-compiler-v2/tests/checking-lang-v1/underscore.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,37 @@ | ||
|
||
Diagnostics: | ||
error: undeclared `_` | ||
┌─ tests/checking-lang-v1/underscore.move:38:9 | ||
│ | ||
38 │ _ // undefined | ||
│ ^ | ||
|
||
error: duplicate declaration of `_` | ||
┌─ tests/checking-lang-v1/underscore.move:41:30 | ||
│ | ||
41 │ public fun test8(_: u64, _: u64): u64 { | ||
│ - ^ | ||
│ │ | ||
│ previous declaration of `_` | ||
|
||
error: duplicate declaration of `_` | ||
┌─ tests/checking-lang-v1/underscore.move:46:37 | ||
│ | ||
46 │ inline fun fun9(x: u64, _: u64, _: u64): u64 { | ||
│ - ^ | ||
│ │ | ||
│ previous declaration of `_` | ||
|
||
error: duplicate declaration of `_` | ||
┌─ tests/checking-lang-v1/underscore.move:54:38 | ||
│ | ||
54 │ inline fun fun10(x: u64, _: u64, _: |u64|u64): u64 { | ||
│ - ^ | ||
│ │ | ||
│ previous declaration of `_` | ||
|
||
error: cannot pass `integer` to a function which expects argument of type `|u64|u64` | ||
┌─ tests/checking-lang-v1/underscore.move:59:21 | ||
│ | ||
59 │ fun10(4, 3, 2) | ||
│ ^ |
101 changes: 101 additions & 0 deletions
101
third_party/move/move-compiler-v2/tests/checking-lang-v1/underscore.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,101 @@ | ||
//# publish | ||
module 0xc0ffee::m { | ||
fun test2(): (u32, u64) { | ||
(1u32, 2u64) | ||
} | ||
|
||
public fun test(_: u64): u64 { | ||
let x = _ + 3; | ||
x + _ | ||
} | ||
|
||
public fun test3(_: u64): u64 { | ||
let (_, _) = test2(); | ||
let x = _ + 3; | ||
_ = _ + 1; | ||
x + _ | ||
} | ||
|
||
public fun test4(_: u64): u64 { | ||
let (_, _x) = test2(); | ||
_ = _ + 2; | ||
_ | ||
} | ||
|
||
public fun test5(_: u64): u64 { | ||
let (_, _) = test2(); | ||
_ = _ + 3; | ||
_ | ||
} | ||
|
||
public fun test6(_: u64): u64 { | ||
let (_x, _) = test2(); | ||
_ | ||
} | ||
|
||
public fun test7(_y: u64): u64 { | ||
let _ = _y; | ||
_ // undefined | ||
} | ||
|
||
public fun test8(_: u64, _: u64): u64 { | ||
let _ = _; | ||
_ | ||
} | ||
|
||
inline fun fun9(x: u64, _: u64, _: u64): u64 { | ||
x + 3 | ||
} | ||
|
||
public fun test9(): u64 { | ||
fun9(4, 3, 2) | ||
} | ||
|
||
inline fun fun10(x: u64, _: u64, _: |u64|u64): u64 { | ||
x + 3 | ||
} | ||
|
||
public fun test10a(): u64 { | ||
fun10(4, 3, 2) | ||
} | ||
|
||
public fun test10b(): u64 { | ||
fun10(4, 3, |x|x + 1) | ||
} | ||
|
||
public fun test10c(): u64 { | ||
fun10(4, 3, |_|1) | ||
} | ||
|
||
inline fun fun11(x: u64, _: u64, f: |u64|u64): u64 { | ||
f(x) | ||
} | ||
|
||
public fun test11(): u64 { | ||
fun11(4, 3, |_|1) | ||
} | ||
} | ||
|
||
//# run 0xc0ffee::m::test --args 4 | ||
|
||
//# run 0xc0ffee::m::test3 --args 5 | ||
|
||
//# run 0xc0ffee::m::test4 --args 5 | ||
|
||
//# run 0xc0ffee::m::test5 --args 5 | ||
|
||
//# run 0xc0ffee::m::test6 --args 5 | ||
|
||
//# run 0xc0ffee::m::test7 --args 5 | ||
|
||
//# run 0xc0ffee::m::test8 --args 5 | ||
|
||
//# run 0xc0ffee::m::test9 | ||
|
||
//# run 0xc0ffee::m::test10a | ||
|
||
//# run 0xc0ffee::m::test10b | ||
|
||
//# run 0xc0ffee::m::test10c | ||
|
||
//# run 0xc0ffee::m::test11 |
85 changes: 85 additions & 0 deletions
85
third_party/move/move-compiler-v2/tests/checking/naming/underscore.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,85 @@ | ||
|
||
Diagnostics: | ||
error: undeclared `_` | ||
┌─ tests/checking/naming/underscore.move:8:17 | ||
│ | ||
8 │ let x = _ + 3; | ||
│ ^ | ||
|
||
error: undeclared `_` | ||
┌─ tests/checking/naming/underscore.move:9:13 | ||
│ | ||
9 │ x + _ | ||
│ ^ | ||
|
||
error: undeclared `_` | ||
┌─ tests/checking/naming/underscore.move:14:17 | ||
│ | ||
14 │ let x = _ + 3; | ||
│ ^ | ||
|
||
error: undeclared `_` | ||
┌─ tests/checking/naming/underscore.move:15:13 | ||
│ | ||
15 │ _ = _ + 1; | ||
│ ^ | ||
|
||
error: undeclared `_` | ||
┌─ tests/checking/naming/underscore.move:16:13 | ||
│ | ||
16 │ x + _ | ||
│ ^ | ||
|
||
error: undeclared `_` | ||
┌─ tests/checking/naming/underscore.move:21:13 | ||
│ | ||
21 │ _ = _ + 2; | ||
│ ^ | ||
|
||
error: undeclared `_` | ||
┌─ tests/checking/naming/underscore.move:22:9 | ||
│ | ||
22 │ _ | ||
│ ^ | ||
|
||
error: undeclared `_` | ||
┌─ tests/checking/naming/underscore.move:27:13 | ||
│ | ||
27 │ _ = _ + 3; | ||
│ ^ | ||
|
||
error: undeclared `_` | ||
┌─ tests/checking/naming/underscore.move:28:9 | ||
│ | ||
28 │ _ | ||
│ ^ | ||
|
||
error: undeclared `_` | ||
┌─ tests/checking/naming/underscore.move:33:10 | ||
│ | ||
33 │ _ | ||
│ ^ | ||
|
||
error: undeclared `_` | ||
┌─ tests/checking/naming/underscore.move:38:9 | ||
│ | ||
38 │ _ // undefined | ||
│ ^ | ||
|
||
error: undeclared `_` | ||
┌─ tests/checking/naming/underscore.move:42:17 | ||
│ | ||
42 │ let _ = _; | ||
│ ^ | ||
|
||
error: undeclared `_` | ||
┌─ tests/checking/naming/underscore.move:43:9 | ||
│ | ||
43 │ _ | ||
│ ^ | ||
|
||
error: cannot pass `integer` to a function which expects argument of type `|u64|u64` | ||
┌─ tests/checking/naming/underscore.move:59:21 | ||
│ | ||
59 │ fun10(4, 3, 2) | ||
│ ^ |
101 changes: 101 additions & 0 deletions
101
third_party/move/move-compiler-v2/tests/checking/naming/underscore.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,101 @@ | ||
//# publish | ||
module 0xc0ffee::m { | ||
fun test2(): (u32, u64) { | ||
(1u32, 2u64) | ||
} | ||
|
||
public fun test(_: u64): u64 { | ||
let x = _ + 3; | ||
x + _ | ||
} | ||
|
||
public fun test3(_: u64): u64 { | ||
let (_, _) = test2(); | ||
let x = _ + 3; | ||
_ = _ + 1; | ||
x + _ | ||
} | ||
|
||
public fun test4(_: u64): u64 { | ||
let (_, _x) = test2(); | ||
_ = _ + 2; | ||
_ | ||
} | ||
|
||
public fun test5(_: u64): u64 { | ||
let (_, _) = test2(); | ||
_ = _ + 3; | ||
_ | ||
} | ||
|
||
public fun test6(_: u64): u64 { | ||
let (_x, _) = test2(); | ||
_ | ||
} | ||
|
||
public fun test7(_y: u64): u64 { | ||
let _ = _y; | ||
_ // undefined | ||
} | ||
|
||
public fun test8(_: u64, _: u64): u64 { | ||
let _ = _; | ||
_ | ||
} | ||
|
||
inline fun fun9(x: u64, _: u64, _: u64): u64 { | ||
x + 3 | ||
} | ||
|
||
public fun test9(): u64 { | ||
fun9(4, 3, 2) | ||
} | ||
|
||
inline fun fun10(x: u64, _: u64, _: |u64|u64): u64 { | ||
x + 3 | ||
} | ||
|
||
public fun test10a(): u64 { | ||
fun10(4, 3, 2) | ||
} | ||
|
||
public fun test10b(): u64 { | ||
fun10(4, 3, |x|x + 1) | ||
} | ||
|
||
public fun test10c(): u64 { | ||
fun10(4, 3, |_|1) | ||
} | ||
|
||
inline fun fun11(x: u64, _: u64, f: |u64|u64): u64 { | ||
f(x) | ||
} | ||
|
||
public fun test11(): u64 { | ||
fun11(4, 3, |_|1) | ||
} | ||
} | ||
|
||
//# run 0xc0ffee::m::test --args 4 | ||
|
||
//# run 0xc0ffee::m::test3 --args 5 | ||
|
||
//# run 0xc0ffee::m::test4 --args 5 | ||
|
||
//# run 0xc0ffee::m::test5 --args 5 | ||
|
||
//# run 0xc0ffee::m::test6 --args 5 | ||
|
||
//# run 0xc0ffee::m::test7 --args 5 | ||
|
||
//# run 0xc0ffee::m::test8 --args 5 | ||
|
||
//# run 0xc0ffee::m::test9 | ||
|
||
//# run 0xc0ffee::m::test10a | ||
|
||
//# run 0xc0ffee::m::test10b | ||
|
||
//# run 0xc0ffee::m::test10c | ||
|
||
//# run 0xc0ffee::m::test11 |
Oops, something went wrong.