mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
This commit is contained in:
parent
9f910643ed
commit
5566df56f1
2 changed files with 27 additions and 1 deletions
|
@ -442,8 +442,9 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
|
||||||
if val.typ_key != '' {
|
if val.typ_key != '' {
|
||||||
val_type = g.type_resolver.get_ct_type_or_default(val.typ_key, var_type)
|
val_type = g.type_resolver.get_ct_type_or_default(val.typ_key, var_type)
|
||||||
}
|
}
|
||||||
} else if val is ast.CallExpr {
|
} else if val is ast.CallExpr && val.return_type_generic.has_flag(.generic) {
|
||||||
g.assign_ct_type = g.comptime.comptime_for_field_type
|
g.assign_ct_type = g.comptime.comptime_for_field_type
|
||||||
|
val_type = var_type
|
||||||
}
|
}
|
||||||
} else if mut left is ast.IndexExpr && val is ast.ComptimeSelector {
|
} else if mut left is ast.IndexExpr && val is ast.ComptimeSelector {
|
||||||
if val.typ_key != '' {
|
if val.typ_key != '' {
|
||||||
|
|
25
vlib/v/tests/comptime/comptime_selector_assign_test.v
Normal file
25
vlib/v/tests/comptime/comptime_selector_assign_test.v
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
module main
|
||||||
|
|
||||||
|
struct AnyStruct[T] {
|
||||||
|
val T
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decode_struct[T]() T {
|
||||||
|
mut typ := T{}
|
||||||
|
$for field in T.fields {
|
||||||
|
typ.$(field.name) = decode_field(typ.$(field.name))
|
||||||
|
}
|
||||||
|
return typ
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decode_field[T](_ T) T {
|
||||||
|
mut field := T{}
|
||||||
|
return field
|
||||||
|
}
|
||||||
|
|
||||||
|
type Any = int | string | []Any
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
decode_struct[AnyStruct[Any]]()
|
||||||
|
decode_struct[AnyStruct[[]Any]]()
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue