// Reflection builtins on an `Any` consult the Any's runtime TYPE-TAG,
// not its raw payload.
//
// An `Any` is both a type AND a value: it can hold a runtime *value*
// (whose runtime tag names the value's type) or a *Type value* (the
// `{ .any, tid }` shape `type_of` / a `Type` literal produce). A
// reflection builtin must branch on the tag:
//   - holds a value   → report the type OF that value (the tag).
//   - holds a Type     → name the held type (the payload).
//
// Regression (issue 0090, attempt 3): `type_name` / `type_is_unsigned`
// used to read an Any's payload as a TypeId index unconditionally, so
// `type_name(av)` for `av : Any = 6` returned `u8` (types[6]) and
// `type_is_unsigned(av)` returned true. Both now read the runtime tag.

#import "modules/std.sx";

main :: () {
    // Any holding a VALUE — reflection names the value's type.
    av : Any = 6;                 // 6 is i64
    print("type_name(av)={}\n", type_name(av));
    print("type_is_unsigned(av)={}\n", type_is_unsigned(av));
    print("print(av)={}\n", av);  // formatter already used the tag

    u : u32 = 7;
    au : Any = u;
    print("type_name(au)={}\n", type_name(au));
    print("type_is_unsigned(au)={}\n", type_is_unsigned(au));
    print("print(au)={}\n", au);

    sv : Any = "hi";
    print("type_name(sv)={}\n", type_name(sv));

    // Any holding a TYPE value — reflection names the held type.
    x : u64 = 9;
    at : Any = type_of(x);
    print("type_name(at)={}\n", type_name(at));
    print("type_is_unsigned(at)={}\n", type_is_unsigned(at));
    print("print(at)={}\n", at);

    // A direct runtime Type value is unchanged.
    print("type_is_unsigned(type_of(x))={}\n", type_is_unsigned(type_of(x)));
}
