This commit is contained in:
Felipe Pena 2025-08-15 08:43:43 -03:00
parent a1b131c99a
commit 5c67e5466e
2 changed files with 32 additions and 0 deletions

View file

@ -0,0 +1,29 @@
module main
struct Demo[T] {
mut:
val T
}
type DemoType = int | []DemoType
fn test_main() {
assert decode[Demo[[]DemoType]]() == Demo[[]DemoType]{}
assert decode[Demo[DemoType]]() == Demo[DemoType]{}
}
fn decode[T]() T {
mut typ := T{}
typ.val = decode_x(typ.val)
return typ
}
fn decode_x[T](_ T) T {
mut field := T{}
$if T is int {
field = 0
} $else $if T is $array {
field = []DemoType{}
}
return field
}

View file

@ -342,6 +342,9 @@ pub fn (mut t TypeResolver) resolve_args(cur_fn &ast.FnDecl, func &ast.Fn, mut n
} else { } else {
comptime_args[k] = ctyp comptime_args[k] = ctyp
} }
} else if mut call_arg.expr is ast.SelectorExpr
&& call_arg.expr.expr_type.has_flag(.generic) {
comptime_args[k] = t.typeof_type(call_arg.expr, call_arg.expr.typ)
} }
} }
return comptime_args return comptime_args