mirror of
https://github.com/vlang/v.git
synced 2025-09-08 23:07:19 -04:00
parent
9fb0685c59
commit
73caa8dff5
@ -467,10 +467,19 @@ fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
|
||||
node.pos)
|
||||
} else {
|
||||
if c.inside_assign && node.is_expr && !node.typ.has_flag(.shared_f)
|
||||
&& stmt.typ.is_ptr() != node.typ.is_ptr()
|
||||
&& stmt.typ != ast.voidptr_type {
|
||||
c.error('mismatched types `${c.table.type_to_str(node.typ)}` and `${c.table.type_to_str(stmt.typ)}`',
|
||||
node.pos)
|
||||
if stmt.typ.is_ptr() != node.typ.is_ptr() {
|
||||
c.error('mismatched types `${c.table.type_to_str(node.typ)}` and `${c.table.type_to_str(stmt.typ)}`',
|
||||
node.pos)
|
||||
} else if stmt.typ != ast.none_type {
|
||||
if !node.typ.has_flag(.option) && stmt.typ.has_flag(.option) {
|
||||
c.error('mismatched types `${c.table.type_to_str(node.typ)}` and `${c.table.type_to_str(stmt.typ)}`',
|
||||
node.pos)
|
||||
} else if !node.typ.has_flag(.result) && stmt.typ.has_flag(.result) {
|
||||
c.error('mismatched types `${c.table.type_to_str(node.typ)}` and `${c.table.type_to_str(stmt.typ)}`',
|
||||
node.pos)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if !node.is_comptime && stmt !in [ast.Return, ast.BranchStmt] {
|
||||
|
12
vlib/v/checker/tests/if_mismatch_option_err.out
Normal file
12
vlib/v/checker/tests/if_mismatch_option_err.out
Normal file
@ -0,0 +1,12 @@
|
||||
vlib/v/checker/tests/if_mismatch_option_err.vv:8:2: warning: unused variable: `operation`
|
||||
6 | fn main() {
|
||||
7 | operation_name := 'get_area'
|
||||
8 | operation := if o := Operation.from(operation_name) { o } else { ?Operation(none) }
|
||||
| ~~~~~~~~~
|
||||
9 | }
|
||||
vlib/v/checker/tests/if_mismatch_option_err.vv:8:15: error: mismatched types `Operation` and `?Operation`
|
||||
6 | fn main() {
|
||||
7 | operation_name := 'get_area'
|
||||
8 | operation := if o := Operation.from(operation_name) { o } else { ?Operation(none) }
|
||||
| ~~
|
||||
9 | }
|
9
vlib/v/checker/tests/if_mismatch_option_err.vv
Normal file
9
vlib/v/checker/tests/if_mismatch_option_err.vv
Normal file
@ -0,0 +1,9 @@
|
||||
enum Operation {
|
||||
get_area
|
||||
get_sector
|
||||
}
|
||||
|
||||
fn main() {
|
||||
operation_name := 'get_area'
|
||||
operation := if o := Operation.from(operation_name) { o } else { ?Operation(none) }
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user