1
0
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:
Felipe Pena 2022-12-27 10:14:58 -03:00 committed by GitHub
parent a8f6f9ed60
commit c5c7b3a054
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -871,7 +871,7 @@ fn (mut c Checker) infer_fn_generic_types(func ast.Fn, mut node ast.CallExpr) {
func_.name = ''
idx := c.table.find_or_register_fn_type(func_, true, false)
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 {
compselector := arg.expr as ast.ComptimeSelector
if compselector.field_expr is ast.SelectorExpr {

View 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
})
}'
}