checker: fix call from unknown enum (fix #23728) (#23730)

This commit is contained in:
Felipe Pena 2025-02-15 15:12:28 -03:00 committed by GitHub
parent f7841e125b
commit ae899e67fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 0 deletions

View File

@ -1154,6 +1154,7 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
}
if idx == 0 {
c.error('unknown enum `${enum_name}`', node.pos)
continue_check = false
return ast.void_type
}

View File

@ -0,0 +1,18 @@
vlib/v/checker/tests/unkown_enum_call_err.vv:8:9: error: unknown enum `HashFnX`
6 |
7 | fn test_main() {
8 | assert HashFnX.from_string('sha256') or { HashFn.sha1 } == HashFn.sha256
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 | }
vlib/v/checker/tests/unkown_enum_call_err.vv:8:39: error: unexpected `or` block, the function `HashFnX__static__from_string` does not return an Option or a Result
6 |
7 | fn test_main() {
8 | assert HashFnX.from_string('sha256') or { HashFn.sha1 } == HashFn.sha256
| ~~~~~~~~~~~~~~~~~~
9 | }
vlib/v/checker/tests/unkown_enum_call_err.vv:8:9: error: assert can be used only with `bool` expressions, but found `void` instead
6 |
7 | fn test_main() {
8 | assert HashFnX.from_string('sha256') or { HashFn.sha1 } == HashFn.sha256
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 | }

View File

@ -0,0 +1,9 @@
enum HashFn {
sha1
sha256
sha512
}
fn test_main() {
assert HashFnX.from_string('sha256') or { HashFn.sha1 } == HashFn.sha256
}