Closed hholst80 closed 6 months ago
Since ;
is now valid in V, this looks like an unreachable code
thing since V will exit because of the panic.
It seems there is also a related issue with nesting?
event := json2.decode[Event](req.data) or {
eprintln(err)
conf := http.ResponseConfig{
status: .internal_server_error
header: http.new_header(http.HeaderConfig{ key: .content_type, value: 'text/plain' })
body: "${err}"
}
con.close() or { panic(err) }
}
src/main.v:40:8: error: `or` block must provide a default value of type `Event`, or return/continue/break or call a [noreturn] function like panic(err) or exit(1)
38 | body: "${err}"
39 | }
40 | con.close() or { panic(err) }
| ~~~~~~~~~~~~~~~~~~~~~~~~~
41 | }
42 | // req := http.parse_request(mut buf_reader)!
EDIT:
I misunderstood the error. The error is resolved by adding a panic after the close statement. The error originated from the first if block.
event := json2.decode[Event](req.data) or {
eprintln(err)
conf := http.ResponseConfig{
status: .internal_server_error
header: http.new_header(http.HeaderConfig{ key: .content_type, value: 'text/plain' })
body: "${err}"
}
con.close() or { panic(err) }
panic(err)
}
Yes, which is a separate error. With the ;
, it looks like unreachable code. Without the ;
, it is wrong in that a default value isn't required since it would exit before that extra code was reached.
Both could be handled by the seeing that it will exit, but it would be more clear to have 2 separate errors.
Oh, and although the ;
is accepted, v fmt
will remove it, as it is not needed for anything (other than some cases with -e
on the command line).
Describe the bug
If I use a semicolon after a
panic("...");
the v compiler will state thatObviously, the type depends on the specific expected return type.
Reproduction Steps
Expected Behavior
The program should compile, or maybe it should complain about unreachable code in foo(), but I did not expect to see an error regarding the if block.
Current Behavior
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.4.5 1aee2b5
Environment details (OS name and version, etc.)