File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -396,6 +396,12 @@ fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
396396 c.error ('mismatched types `${c.table.type_to_str(node.typ)} ` and `${c.table.type_to_str(stmt.typ)} `' ,
397397 node.pos)
398398 } else {
399+ if ! node.typ.has_option_or_result () && ! node.typ.has_flag (.shared_f)
400+ && stmt.typ != ast.voidptr_type
401+ && stmt.typ.nr_muls () != node.typ.nr_muls () {
402+ c.error ('mismatched types `${c.table.type_to_str(node.typ)} ` and `${c.table.type_to_str(stmt.typ)} `' ,
403+ node.pos)
404+ }
399405 if node.is_expr == false && c.type_resolver.is_generic_param_var (stmt.expr) {
400406 // generic variable no yet type bounded
401407 node.is_expr = true
Original file line number Diff line number Diff line change 1+ vlib/v/checker/tests/if_mismatch_muls_err.vv:17:11: error: mismatched types `&&Dum` and `&Dum`
2+ 15 |
3+ 16 | fn main() {
4+ 17 | dummy := if false {
5+ | ~~
6+ 18 | res := &Dum{
7+ 19 | v: 2
Original file line number Diff line number Diff line change 1+ module main
2+
3+ struct Dummy {
4+ v int
5+ }
6+
7+ fn get_dummy() &Dum {
8+ d := Dum{
9+ v: 1
10+ }
11+ return &d
12+ }
13+
14+ type Dum = Dummy
15+
16+ fn main() {
17+ dummy := if false {
18+ res := &Dum{
19+ v: 2
20+ }
21+ &res
22+ } else {
23+ r := get_dummy()
24+ r
25+ }
26+
27+ println(dummy)
28+ }
You can’t perform that action at this time.
0 commit comments