diff --git a/vlib/v/checker/comptime.v b/vlib/v/checker/comptime.v index 5544976205..8353e37658 100644 --- a/vlib/v/checker/comptime.v +++ b/vlib/v/checker/comptime.v @@ -171,7 +171,7 @@ fn (mut c Checker) comptime_selector(mut node ast.ComptimeSelector) ast.Type { fn (mut c Checker) comptime_for(node ast.ComptimeFor) { typ := c.unwrap_generic(node.typ) - sym := c.table.sym(typ) + sym := c.table.final_sym(typ) if sym.kind == .placeholder || typ.has_flag(.generic) { c.error('unknown type `${sym.name}`', node.typ_pos) } diff --git a/vlib/v/gen/c/comptime.v b/vlib/v/gen/c/comptime.v index b90eeea45b..e634524457 100644 --- a/vlib/v/gen/c/comptime.v +++ b/vlib/v/gen/c/comptime.v @@ -507,7 +507,7 @@ fn (mut g Gen) comptime_if_cond(cond ast.Expr, pkg_exist bool) bool { } fn (mut g Gen) comptime_for(node ast.ComptimeFor) { - sym := g.table.sym(g.unwrap_generic(node.typ)) + sym := g.table.final_sym(g.unwrap_generic(node.typ)) g.writeln('/* \$for ${node.val_var} in ${sym.name}(${node.kind.str()}) */ {') g.indent++ // vweb_result_type := ast.new_type(g.table.find_type_idx('vweb.Result')) diff --git a/vlib/v/tests/forcomp_alias_type_test.v b/vlib/v/tests/forcomp_alias_type_test.v new file mode 100644 index 0000000000..80e84dec74 --- /dev/null +++ b/vlib/v/tests/forcomp_alias_type_test.v @@ -0,0 +1,25 @@ +module main + +struct Aa { + sub AliasType +} + +type AliasType = Bb + +struct Bb { + a int +} + +fn encode_struct[U](val U, mut out []string) []string { + $for field in U.fields { + encode_struct(val.$(field.name), mut out) + out << field.str() + } + return out +} + +fn test_main() { + aa := Aa{} + mut out := []string{} + assert encode_struct(aa, mut out).len == 2 +}