From bd139dc09c2a66ffdd6bbff98ffbc197ac782e16 Mon Sep 17 00:00:00 2001 From: agra Date: Tue, 16 Jun 2026 19:01:03 +0300 Subject: [PATCH] =?UTF-8?q?xfail(reify):=20field=5Ftype=20=E2=80=94=20read?= =?UTF-8?q?=20struct/enum=20member=20types=20by=20index?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit REIFY Phase 2.0. Add examples/0616: reflect a struct's fields (name via field_name, type via field_type) and a tagged-union's variant payloads, including field_type composed inside type_eq / type_name. Seed an empty expected/*.exit marker. RED by design — field_type still bails ("not yet implemented"); Phase 2.1 implements it over the type table and turns this green. --- examples/0616-comptime-field-type.sx | 29 +++++++++++++++++++ .../expected/0616-comptime-field-type.exit | 0 2 files changed, 29 insertions(+) create mode 100644 examples/0616-comptime-field-type.sx create mode 100644 examples/expected/0616-comptime-field-type.exit diff --git a/examples/0616-comptime-field-type.sx b/examples/0616-comptime-field-type.sx new file mode 100644 index 00000000..846a5c92 --- /dev/null +++ b/examples/0616-comptime-field-type.sx @@ -0,0 +1,29 @@ +// REIFY Phase 2: `field_type($T, i) -> Type` — the type-only field projection +// the value-level reflection (`field_value` / `type_of`) couldn't express. +// Reflect a struct's fields by name (`field_name`) AND by type (`field_type`), +// and a tagged-union's variant payloads. It folds at lower time, so it composes +// inside `type_eq` / `type_name` / any type-arg slot. +#import "modules/std.sx"; +#import "modules/std/meta.sx"; + +Point :: struct { x: i64; y: f64; on: bool; } + +Msg :: enum { num: i64; tag: bool; quit; } + +main :: () -> i32 { + // Struct fields: name + type, position by position. + print("Point has {} fields\n", field_count(Point)); + print(" 0: {} : {}\n", field_name(Point, 0), type_name(field_type(Point, 0))); + print(" 1: {} : {}\n", field_name(Point, 1), type_name(field_type(Point, 1))); + print(" 2: {} : {}\n", field_name(Point, 2), type_name(field_type(Point, 2))); + + // field_type composes in a type-arg slot (type_eq folds at comptime). + print("field 0 is i64: {}\n", type_eq(field_type(Point, 0), i64)); + print("field 1 is f64: {}\n", type_eq(field_type(Point, 1), f64)); + + // Tagged-union variant payloads (the tagless `quit` → void). + print("Msg.num payload: {}\n", type_name(field_type(Msg, 0))); + print("Msg.tag payload: {}\n", type_name(field_type(Msg, 1))); + print("Msg.quit payload: {}\n", type_name(field_type(Msg, 2))); + return 0; +} diff --git a/examples/expected/0616-comptime-field-type.exit b/examples/expected/0616-comptime-field-type.exit new file mode 100644 index 00000000..e69de29b