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:
parent
f4cd3931fb
commit
c10bc09e83
@ -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)
|
||||
}
|
||||
|
@ -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'))
|
||||
|
25
vlib/v/tests/forcomp_alias_type_test.v
Normal file
25
vlib/v/tests/forcomp_alias_type_test.v
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user