mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check sumtype in unknown type (#17225)
This commit is contained in:
parent
c40e25b028
commit
fc65de9bba
@ -165,6 +165,12 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
||||
c.error('left operand to `${node.op}` does not match the array element type: ${err.msg()}',
|
||||
left_right_pos)
|
||||
}
|
||||
} else {
|
||||
if mut node.right is ast.ArrayInit {
|
||||
for i, typ in node.right.expr_types {
|
||||
c.ensure_type_exists(typ, node.right.exprs[i].pos()) or {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.map {
|
||||
|
8
vlib/v/checker/tests/sumtype_in_unknown_types_err.out
Normal file
8
vlib/v/checker/tests/sumtype_in_unknown_types_err.out
Normal file
@ -0,0 +1,8 @@
|
||||
vlib/v/checker/tests/sumtype_in_unknown_types_err.vv:11:25: error: unknown type `FooD`.
|
||||
Did you mean `Foo`?
|
||||
9 | fn main() {
|
||||
10 | foo := Foo(FooA{})
|
||||
11 | if foo in [FooB, FooC, FooD] {
|
||||
| ~~~~
|
||||
12 | panic('not possible')
|
||||
13 | } else {
|
16
vlib/v/checker/tests/sumtype_in_unknown_types_err.vv
Normal file
16
vlib/v/checker/tests/sumtype_in_unknown_types_err.vv
Normal file
@ -0,0 +1,16 @@
|
||||
type Foo = FooA | FooB | FooC
|
||||
|
||||
struct FooA {}
|
||||
|
||||
struct FooB {}
|
||||
|
||||
struct FooC {}
|
||||
|
||||
fn main() {
|
||||
foo := Foo(FooA{})
|
||||
if foo in [FooB, FooC, FooD] {
|
||||
panic('not possible')
|
||||
} else {
|
||||
println('ok')
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user