mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
table: check sumtype of fntype assign error (#15685)
This commit is contained in:
parent
2693935066
commit
8627af18dd
@ -1308,7 +1308,14 @@ pub fn (t &Table) sumtype_has_variant(parent Type, variant Type, is_as bool) boo
|
|||||||
|
|
||||||
fn (t &Table) sumtype_check_function_variant(parent_info SumType, variant Type, is_as bool) bool {
|
fn (t &Table) sumtype_check_function_variant(parent_info SumType, variant Type, is_as bool) bool {
|
||||||
for v in parent_info.variants {
|
for v in parent_info.variants {
|
||||||
if '$v.idx' == '$variant.idx' && (!is_as || v.nr_muls() == variant.nr_muls()) {
|
v_sym := t.sym(v)
|
||||||
|
if v_sym.kind != .function {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
v_fn := (v_sym.info as FnType).func
|
||||||
|
variant_fn := (t.sym(variant).info as FnType).func
|
||||||
|
if t.fn_type_source_signature(v_fn) == t.fn_type_source_signature(variant_fn)
|
||||||
|
&& (!is_as || v.nr_muls() == variant.nr_muls()) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
vlib/v/checker/tests/sumtype_of_fntype_assign_err.out
Normal file
6
vlib/v/checker/tests/sumtype_of_fntype_assign_err.out
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
vlib/v/checker/tests/sumtype_of_fntype_assign_err.vv:14:11: error: cannot assign to `m['f']`: expected `Expr`, not `fn () Expr`
|
||||||
|
12 | mut m := map[string]Expr{}
|
||||||
|
13 |
|
||||||
|
14 | m['f'] = f
|
||||||
|
| ^
|
||||||
|
15 | }
|
15
vlib/v/checker/tests/sumtype_of_fntype_assign_err.vv
Normal file
15
vlib/v/checker/tests/sumtype_of_fntype_assign_err.vv
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
type Expr = fn (int) int | int
|
||||||
|
|
||||||
|
fn id(n int) int {
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
fn f() Expr {
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
mut m := map[string]Expr{}
|
||||||
|
|
||||||
|
m['f'] = f
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user