From 60471b3a2c1553e472196549837371b6db0de5eb Mon Sep 17 00:00:00 2001 From: agra Date: Wed, 17 Jun 2026 05:15:43 +0300 Subject: [PATCH] test(metatype): comptime subslice over an aggregate (examples/0621) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit make_enum from dirs[0..2] — mints Axis from a comptime SUBSLICE of a local EnumVariant array. Locks the interp subslice-over-non-string- aggregate fix (d22037c); previously bailed. --- ...0621-comptime-metatype-make-enum-sliced.sx | 30 +++++++++++++++++++ ...21-comptime-metatype-make-enum-sliced.exit | 1 + ...-comptime-metatype-make-enum-sliced.stderr | 1 + ...-comptime-metatype-make-enum-sliced.stdout | 2 ++ 4 files changed, 34 insertions(+) create mode 100644 examples/0621-comptime-metatype-make-enum-sliced.sx create mode 100644 examples/expected/0621-comptime-metatype-make-enum-sliced.exit create mode 100644 examples/expected/0621-comptime-metatype-make-enum-sliced.stderr create mode 100644 examples/expected/0621-comptime-metatype-make-enum-sliced.stdout diff --git a/examples/0621-comptime-metatype-make-enum-sliced.sx b/examples/0621-comptime-metatype-make-enum-sliced.sx new file mode 100644 index 00000000..bd8acc4d --- /dev/null +++ b/examples/0621-comptime-metatype-make-enum-sliced.sx @@ -0,0 +1,30 @@ +// Comptime slice over a non-string AGGREGATE: assemble a pool of candidate +// variants in a local array, then mint an enum from a SUBSLICE of it. This +// exercises the interp's `subslice` op on an array VALUE (`dirs[0..2]`) — which +// used to bail ("slice over non-string aggregates not yet supported") — now +// yielding a real `[]EnumVariant` the `define` decoder reads. +// +// `Axis` is built from only the first two of four directions, so `.south` / +// `.west` are NOT variants of it. +#import "modules/std.sx"; +#import "modules/std/meta.sx"; + +build_axis :: () -> Type { + dirs := EnumVariant.[ + EnumVariant.{ name = "north", payload = void }, + EnumVariant.{ name = "east", payload = i64 }, // carries a bearing + EnumVariant.{ name = "south", payload = void }, + EnumVariant.{ name = "west", payload = void }, + ]; + return make_enum("Axis", dirs[0..2]); // first two only — a comptime subslice +} + +Axis :: build_axis(); + +main :: () -> i32 { + a : Axis = .north; + b : Axis = .east(90); + if a == { case .north: { print("north\n"); } case .east: (d) { print("east {}\n", d); } } + if b == { case .north: { print("north\n"); } case .east: (d) { print("east {}\n", d); } } + return 0; +} diff --git a/examples/expected/0621-comptime-metatype-make-enum-sliced.exit b/examples/expected/0621-comptime-metatype-make-enum-sliced.exit new file mode 100644 index 00000000..573541ac --- /dev/null +++ b/examples/expected/0621-comptime-metatype-make-enum-sliced.exit @@ -0,0 +1 @@ +0 diff --git a/examples/expected/0621-comptime-metatype-make-enum-sliced.stderr b/examples/expected/0621-comptime-metatype-make-enum-sliced.stderr new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/examples/expected/0621-comptime-metatype-make-enum-sliced.stderr @@ -0,0 +1 @@ + diff --git a/examples/expected/0621-comptime-metatype-make-enum-sliced.stdout b/examples/expected/0621-comptime-metatype-make-enum-sliced.stdout new file mode 100644 index 00000000..e83689fe --- /dev/null +++ b/examples/expected/0621-comptime-metatype-make-enum-sliced.stdout @@ -0,0 +1,2 @@ +north +east 90