feat(metatype): comptime-eval generic type-fn body locals

A generic ($T) -> Type type-fn comptime-evaluated only its return
EXPRESSION, so a local declared before the return ('vs := …; return
make_enum(…, vs)') was unresolved. Now a body with a prelude (statements
before the return) has its full body evaluated: createComptimeFunction-
WithPrelude lowers the pre-return statements into the comptime function's
scope before the return expr, so the locals resolve.

- comptime.zig: createComptimeFunctionWithPrelude (prelude stmts +
  expr); evalComptimeTypeBody (extract prelude + return expr, scan the
  whole body for declare() forward types); runComptimeTypeFunc factored
  out of evalComptimeType (shared bail/declare-never-defined handling).
- generic.zig: route a type-fn body WITH a prelude through
  evalComptimeTypeBody; no-prelude bodies stay on evalComptimeType (zero
  change for RecvResult/TryResult etc.).

Non-generic builders (whole body already evaluated) and the List-growth
path are unaffected. Suite green (684).
This commit is contained in:
agra
2026-06-17 07:40:09 +03:00
parent 60293bf5dd
commit d87d86df8a
3 changed files with 66 additions and 3 deletions

View File

@@ -1567,6 +1567,8 @@ pub const Lowering = struct {
pub const evalComptimeInt = lower_comptime.evalComptimeInt;
pub const evalComptimeString = lower_comptime.evalComptimeString;
pub const evalComptimeType = lower_comptime.evalComptimeType;
pub const evalComptimeTypeBody = lower_comptime.evalComptimeTypeBody;
pub const runComptimeTypeFunc = lower_comptime.runComptimeTypeFunc;
pub const renameNominalType = lower_comptime.renameNominalType;
pub const lowerComptimeGlobal = lower_comptime.lowerComptimeGlobal;
pub const lowerComptimeSideEffect = lower_comptime.lowerComptimeSideEffect;
@@ -1578,6 +1580,7 @@ pub const Lowering = struct {
pub const substituteComptimeNodes = lower_comptime.substituteComptimeNodes;
pub const fnBodyHasReturn = lower_comptime.fnBodyHasReturn;
pub const createComptimeFunction = lower_comptime.createComptimeFunction;
pub const createComptimeFunctionWithPrelude = lower_comptime.createComptimeFunctionWithPrelude;
pub const constExprValue = lower_comptime.constExprValue;
pub const constArrayLiteral = lower_comptime.constArrayLiteral;
pub const constStructLiteral = lower_comptime.constStructLiteral;