fix: resolve qualified-import-member const as a compile-time constant (issue 0192)
A namespaced import's const (`m :: #import "lib.sx"; … m.CAP`) only ever resolved as a runtime value — the const folders in program_index.zig had no namespace-member arm, so a qualified const was rejected as an array dimension / Vector lane / generic value-param and could not seed another const, while the flat-import form worked everywhere. Add a `lookupQualifiedConst` (+ float / float-typed twins) ctx hook: resolve the alias via `namespaceAliasVerdictFrom` to its target module, then fold the member from that module's per-source const cache (`foldQualifiedConstInt` in lower/comptime.zig), pinned to the target source so nested const RHSs fold there. Wire it into evalConstIntExpr / evalConstFloatExpr / isFloatValuedExpr — both the expression-position field_access arm (`[m.CAP]T`) and the type-argument dotted-name arm (`Vector(m.LANES, …)`, generic value-params). Implemented on the source-aware ctxs (Lowering / SourceConstCtx); the namespace-blind ModuleConstCtx / StatelessInner return null, so a qualified-const dim reached only via the stateless type-alias path stays a clean unresolved-dim diagnostic, never a fabricated length. Resolves correctly for array dims, arithmetic, integral-float dims, Vector lanes, generic value-params, inline-for bounds, and struct fields. Regression: examples/modules/0842-modules-qualified-import-const-comptime.sx.
This commit is contained in:
@@ -188,6 +188,17 @@ const DimCtx = struct {
|
||||
pub fn nameIsFloatTyped(_: DimCtx, name: []const u8) bool {
|
||||
return std.mem.eql(u8, name, "F") or std.mem.eql(u8, name, "K");
|
||||
}
|
||||
// This test ctx models no namespace imports — qualified-member consts
|
||||
// (`m.CAP`, issue 0192) are exercised end-to-end by the corpus, not here.
|
||||
pub fn lookupQualifiedConst(_: DimCtx, _: []const u8, _: []const u8) ?i64 {
|
||||
return null;
|
||||
}
|
||||
pub fn lookupQualifiedConstFloat(_: DimCtx, _: []const u8, _: []const u8) ?f64 {
|
||||
return null;
|
||||
}
|
||||
pub fn qualifiedNameIsFloatTyped(_: DimCtx, _: []const u8, _: []const u8) bool {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
fn nLit(v: i64) ast.Node {
|
||||
|
||||
Reference in New Issue
Block a user