Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checker: improve error messages for number casts used as branch value…
…s in match expressions (#20111)
- Loading branch information
Showing
7 changed files
with
134 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
vlib/v/checker/tests/match_incorrect_cast_branch_err.vv:5:9: error: the type of the last expression in the first match branch was an explicit `u8`, not `u16` | ||
3 | nb := match name { | ||
4 | 'a' { u8(10) } | ||
5 | 'b' { u16(500) } | ||
| ~~~~~~~~ | ||
6 | else { u8(0) } | ||
7 | } |
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 @@ | ||
fn main () { | ||
name := 'b' | ||
nb := match name { | ||
'a' { u8(10) } | ||
'b' { u16(500) } | ||
else { u8(0) } | ||
} | ||
|
||
println(nb) | ||
} |
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 @@ | ||
vlib/v/checker/tests/match_last_branch_only_casted.vv:6:10: error: the type of the last expression of the first match branch was `int literal`, which is not compatible with `u64` | ||
4 | 'a' { 10 } | ||
5 | 'b' { 500 } | ||
6 | else { u64(345454) } | ||
| ~~~~~~~~~~~ | ||
7 | } | ||
8 | |
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 @@ | ||
fn main () { | ||
name := 'b' | ||
nb := match name { | ||
'a' { 10 } | ||
'b' { 500 } | ||
else { u64(345454) } | ||
} | ||
|
||
println(nb) | ||
} |
7 changes: 7 additions & 0 deletions
7
vlib/v/checker/tests/match_no_branch_cast_rest_casted_err.out
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 @@ | ||
vlib/v/checker/tests/match_no_branch_cast_rest_casted_err.vv:5:9: error: 345 does not fit the range of `u8` | ||
3 | nb := match name { | ||
4 | 'a' { u8(10) } | ||
5 | 'b' { 345 } | ||
| ~~~ | ||
6 | else { 0 } | ||
7 | } |
10 changes: 10 additions & 0 deletions
10
vlib/v/checker/tests/match_no_branch_cast_rest_casted_err.vv
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 @@ | ||
fn main () { | ||
name := 'b' | ||
nb := match name { | ||
'a' { u8(10) } | ||
'b' { 345 } | ||
else { 0 } | ||
} | ||
|
||
println(nb) | ||
} |