mirror of
https://github.com/vlang/v.git
synced 2025-09-16 10:57:25 -04:00
checker: fix comptime dumping var (#19887)
This commit is contained in:
parent
1482a2f28d
commit
8c8df9e806
@ -135,6 +135,7 @@ mut:
|
||||
comptime_call_pos int // needed for correctly checking use before decl for templates
|
||||
goto_labels map[string]ast.GotoLabel // to check for unused goto labels
|
||||
enum_data_type ast.Type
|
||||
field_data_type ast.Type
|
||||
fn_return_type ast.Type
|
||||
orm_table_fields map[string][]ast.StructField // known table structs
|
||||
//
|
||||
@ -1470,7 +1471,7 @@ fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type {
|
||||
return ast.void_type
|
||||
} else if c.inside_comptime_for_field && typ == c.enum_data_type && node.field_name == 'value' {
|
||||
// for comp-time enum.values
|
||||
node.expr_type = c.comptime_fields_type[c.comptime_for_field_var]
|
||||
node.expr_type = c.comptime_fields_type['${c.comptime_for_field_var}.typ']
|
||||
node.typ = typ
|
||||
return node.expr_type
|
||||
}
|
||||
|
@ -275,9 +275,13 @@ fn (mut c Checker) comptime_for(mut node ast.ComptimeFor) {
|
||||
}
|
||||
c.inside_comptime_for_field = true
|
||||
for field in fields {
|
||||
if c.field_data_type == 0 {
|
||||
c.field_data_type = ast.Type(c.table.find_type_idx('FieldData'))
|
||||
}
|
||||
c.comptime_for_field_value = field
|
||||
c.comptime_for_field_var = node.val_var
|
||||
c.comptime_fields_type[node.val_var] = node.typ
|
||||
c.comptime_fields_type[node.val_var] = c.field_data_type
|
||||
c.comptime_fields_type['${node.val_var}.typ'] = node.typ
|
||||
c.comptime_fields_default_type = field.typ
|
||||
c.stmts(mut node.stmts)
|
||||
|
||||
@ -310,7 +314,8 @@ fn (mut c Checker) comptime_for(mut node ast.ComptimeFor) {
|
||||
for field in sym_info.vals {
|
||||
c.comptime_enum_field_value = field
|
||||
c.comptime_for_field_var = node.val_var
|
||||
c.comptime_fields_type[node.val_var] = node.typ
|
||||
c.comptime_fields_type[node.val_var] = c.enum_data_type
|
||||
c.comptime_fields_type['${node.val_var}.typ'] = node.typ
|
||||
c.stmts(mut node.stmts)
|
||||
}
|
||||
} else {
|
||||
|
48
vlib/v/tests/comptime_dump_test.v
Normal file
48
vlib/v/tests/comptime_dump_test.v
Normal file
@ -0,0 +1,48 @@
|
||||
@[abc]
|
||||
struct Another {
|
||||
a []int
|
||||
b u8
|
||||
c u32
|
||||
}
|
||||
|
||||
fn (f Another) test() {}
|
||||
|
||||
enum Abc {
|
||||
a
|
||||
b
|
||||
c
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
mut c := 0
|
||||
$for f in Abc.values {
|
||||
dump(f)
|
||||
dump(f.value)
|
||||
c += 1
|
||||
assert typeof(f).name == 'EnumData'
|
||||
}
|
||||
assert c == 3
|
||||
|
||||
$for f in Another.fields {
|
||||
dump(f)
|
||||
dump(f.name)
|
||||
c += 1
|
||||
}
|
||||
assert c == 6
|
||||
|
||||
$for f in Another.methods {
|
||||
dump(f)
|
||||
dump(f.name)
|
||||
c += 1
|
||||
assert typeof(f).name == 'FunctionData'
|
||||
}
|
||||
assert c == 7
|
||||
|
||||
$for f in Another.attributes {
|
||||
dump(f)
|
||||
dump(f.name)
|
||||
c += 1
|
||||
assert typeof(f).name == 'StructAttribute'
|
||||
}
|
||||
assert c == 8
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user