1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker, cgen: allow $for in alias type (#16810)

This commit is contained in:
Felipe Pena 2022-12-30 06:27:01 -03:00 committed by GitHub
parent f4cd3931fb
commit c10bc09e83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 2 deletions

View File

@ -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)
}

View File

@ -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'))

View File

@ -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
}