mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix comptime var param passing with comptime selector (#16777)
This commit is contained in:
parent
a8f6f9ed60
commit
c5c7b3a054
@ -871,7 +871,7 @@ fn (mut c Checker) infer_fn_generic_types(func ast.Fn, mut node ast.CallExpr) {
|
|||||||
func_.name = ''
|
func_.name = ''
|
||||||
idx := c.table.find_or_register_fn_type(func_, true, false)
|
idx := c.table.find_or_register_fn_type(func_, true, false)
|
||||||
typ = ast.new_type(idx).derive(arg.typ)
|
typ = ast.new_type(idx).derive(arg.typ)
|
||||||
} else if c.inside_comptime_for_field && sym.info is ast.Struct
|
} else if c.inside_comptime_for_field && sym.kind in [.struct_, .any]
|
||||||
&& arg.expr is ast.ComptimeSelector {
|
&& arg.expr is ast.ComptimeSelector {
|
||||||
compselector := arg.expr as ast.ComptimeSelector
|
compselector := arg.expr as ast.ComptimeSelector
|
||||||
if compselector.field_expr is ast.SelectorExpr {
|
if compselector.field_expr is ast.SelectorExpr {
|
||||||
|
26
vlib/v/tests/comptime_var_param_test.v
Normal file
26
vlib/v/tests/comptime_var_param_test.v
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
struct Aa {
|
||||||
|
sub AliasType
|
||||||
|
}
|
||||||
|
|
||||||
|
type AliasType = Bb
|
||||||
|
|
||||||
|
struct Bb {
|
||||||
|
a int
|
||||||
|
}
|
||||||
|
|
||||||
|
fn encode_struct[U](val U) string {
|
||||||
|
$for field in U.fields {
|
||||||
|
encode_struct(val.$(field.name))
|
||||||
|
}
|
||||||
|
return val.str()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
aa := Aa{}
|
||||||
|
|
||||||
|
assert encode_struct(aa) == 'Aa{
|
||||||
|
sub: AliasType(Bb{
|
||||||
|
a: 0
|
||||||
|
})
|
||||||
|
}'
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user