mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
fix
This commit is contained in:
parent
d5e28a827d
commit
0a808f1f26
1 changed files with 24 additions and 25 deletions
|
@ -321,19 +321,17 @@ fn (mut c Checker) comptime_for(mut node ast.ComptimeFor) {
|
||||||
} else if node.kind == .values {
|
} else if node.kind == .values {
|
||||||
if sym.kind == .enum {
|
if sym.kind == .enum {
|
||||||
if sym.info is ast.Enum {
|
if sym.info is ast.Enum {
|
||||||
if sym.info.vals.len > 0 {
|
for _ in sym.info.vals {
|
||||||
for _ in sym.info.vals {
|
c.push_new_comptime_info()
|
||||||
c.push_new_comptime_info()
|
c.comptime.inside_comptime_for = true
|
||||||
c.comptime.inside_comptime_for = true
|
if c.enum_data_type == 0 {
|
||||||
if c.enum_data_type == 0 {
|
c.enum_data_type = c.table.find_type('EnumData')
|
||||||
c.enum_data_type = c.table.find_type('EnumData')
|
|
||||||
}
|
|
||||||
c.comptime.comptime_for_enum_var = node.val_var
|
|
||||||
c.type_resolver.update_ct_type(node.val_var, c.enum_data_type)
|
|
||||||
c.type_resolver.update_ct_type('${node.val_var}.typ', node.typ)
|
|
||||||
c.stmts(mut node.stmts)
|
|
||||||
c.pop_comptime_info()
|
|
||||||
}
|
}
|
||||||
|
c.comptime.comptime_for_enum_var = node.val_var
|
||||||
|
c.type_resolver.update_ct_type(node.val_var, c.enum_data_type)
|
||||||
|
c.type_resolver.update_ct_type('${node.val_var}.typ', node.typ)
|
||||||
|
c.stmts(mut node.stmts)
|
||||||
|
c.pop_comptime_info()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -343,20 +341,18 @@ fn (mut c Checker) comptime_for(mut node ast.ComptimeFor) {
|
||||||
}
|
}
|
||||||
} else if node.kind == .methods {
|
} else if node.kind == .methods {
|
||||||
methods := sym.get_methods()
|
methods := sym.get_methods()
|
||||||
if methods.len > 0 {
|
for method in methods {
|
||||||
for method in methods {
|
c.push_new_comptime_info()
|
||||||
c.push_new_comptime_info()
|
c.comptime.inside_comptime_for = true
|
||||||
c.comptime.inside_comptime_for = true
|
c.comptime.comptime_for_method = unsafe { &method }
|
||||||
c.comptime.comptime_for_method = unsafe { &method }
|
c.comptime.comptime_for_method_var = node.val_var
|
||||||
c.comptime.comptime_for_method_var = node.val_var
|
c.comptime.comptime_for_method_ret_type = method.return_type
|
||||||
c.comptime.comptime_for_method_ret_type = method.return_type
|
c.type_resolver.update_ct_type('${node.val_var}.return_type', method.return_type)
|
||||||
c.type_resolver.update_ct_type('${node.val_var}.return_type', method.return_type)
|
for j, arg in method.params[1..] {
|
||||||
for j, arg in method.params[1..] {
|
c.type_resolver.update_ct_type('${node.val_var}.args[${j}].typ', arg.typ.idx())
|
||||||
c.type_resolver.update_ct_type('${node.val_var}.args[${j}].typ', arg.typ.idx())
|
|
||||||
}
|
|
||||||
c.stmts(mut node.stmts)
|
|
||||||
c.pop_comptime_info()
|
|
||||||
}
|
}
|
||||||
|
c.stmts(mut node.stmts)
|
||||||
|
c.pop_comptime_info()
|
||||||
}
|
}
|
||||||
} else if node.kind == .params {
|
} else if node.kind == .params {
|
||||||
if !(sym.kind == .function || sym.name == 'FunctionData') {
|
if !(sym.kind == .function || sym.name == 'FunctionData') {
|
||||||
|
@ -365,6 +361,9 @@ fn (mut c Checker) comptime_for(mut node ast.ComptimeFor) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
method := c.comptime.comptime_for_method
|
method := c.comptime.comptime_for_method
|
||||||
|
// example: fn (mut d MyStruct) add(x int, y int) string
|
||||||
|
// `d` is params[0], `x` is params[1], `y` is params[2]
|
||||||
|
// so we at least has one param (`d`) for method
|
||||||
for param in method.params[1..] {
|
for param in method.params[1..] {
|
||||||
c.push_new_comptime_info()
|
c.push_new_comptime_info()
|
||||||
c.comptime.inside_comptime_for = true
|
c.comptime.inside_comptime_for = true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue