diff --git a/TODO.md b/TODO.md index 5d826cb..8e6f4ca 100644 --- a/TODO.md +++ b/TODO.md @@ -943,10 +943,9 @@ identically during comptime evaluation; zeroing is `memset!(destination, 0)` - `std/mem` aligned reallocation uses `memcopy!` -46. fix `EnumFieldStruct` in `std/meta` - - currently, the `|info|` `.enum` payload capture doesn't preserve the comptime-ness in the match statement - this results in having to type other values in the scope like `[field!(typeinfo!(E), "enum").fields.len]mut []u8` - which is obviously absurd +46. fix `EnumFieldStruct` in `std/meta` (implemented) + - comptime local declarations resolve type syntax in the active interpreter state, preserving match captures + - `EnumFieldStruct` sizes its working arrays directly from the comptime `.enum |info|` capture ## A word on unchecked casts diff --git a/compiler/checker/comptime.odin b/compiler/checker/comptime.odin index f95514c..be71a34 100644 --- a/compiler/checker/comptime.odin +++ b/compiler/checker/comptime.odin @@ -3873,7 +3873,7 @@ ct_exec_statements :: proc( ok = value_ok if ok && value_flow.kind == .Yield { value := value_flow.value - declared := type_from_syntax(checker, statement.type, state.pkg, state.file) + declared := type_from_syntax(checker, statement.type, state.pkg, state.file, active_state=state) if types.is_valid(declared) && !types.is_void(declared) { value, ok = ct_coerce_value(state, value, declared, statement.span) } @@ -3884,7 +3884,7 @@ ct_exec_statements :: proc( ok = ct_fail(state, .Not_Comptime, statement.span, "comptime value block must yield") } } else { - declared := type_from_syntax(checker, statement.type, state.pkg, state.file) + declared := type_from_syntax(checker, statement.type, state.pkg, state.file, active_state=state) expected := declared if types.is_valid(declared) && !types.is_void(declared) else types.INVALID value, expr_flow, expr_ok := ct_eval_expr(state, statement.expr, expected, depth+1) ok = expr_ok diff --git a/std/meta/meta.bro b/std/meta/meta.bro index 170818d..82d0d53 100644 --- a/std/meta/meta.bro +++ b/std/meta/meta.bro @@ -43,9 +43,9 @@ TypeInfo :: union(enum) { EnumFieldStruct func($E, $Field type, $default ?Field) type { match typeinfo!(E) { .enum |info|: { - names [field!(typeinfo!(E), "enum").fields.len]mut []u8 = undefined - field_types [field!(typeinfo!(E), "enum").fields.len]mut type = undefined - defaults [field!(typeinfo!(E), "enum").fields.len]mut ?Field = undefined + names [info.fields.len]mut []u8 = undefined + field_types [info.fields.len]mut type = undefined + defaults [info.fields.len]mut ?Field = undefined expand for info.fields |field, index| { names[index] = field.name field_types[index] = Field