fix(ir): value const used as a type must not satisfy unknown-type check (issue 0068)
The A2.4 unknown-type pass (semantic_diagnostics) added EVERY const_decl name to
its declared-type-name set. A value const (`NotAType :: 123`) thus satisfied
reportIfUnknownType, so `v: NotAType` was not flagged; lowering then hit
TypeResolver.resolveNamed's empty-struct-stub fallback and fabricated
`NotAType{}` (the program ran, printing it).
Fix: collectDeclaredTypeNames and harvestScopeDecls now gate the const-name-add
on a new constValueIntroducesType — true only when the value introduces a type
(declarations: struct/enum/union/error; type-expression aliases: type_expr,
pointer/many-pointer/slice/optional/array/function/closure/tuple, parameterized).
`.identifier` / `.call` aliases are intentionally excluded: the scan registers
the type-valued ones into ProgramIndex.type_alias_map / the TypeTable (both
queried separately by the pass), so a value-RHS alias is correctly left out and
flagged, while a type-RHS alias stays covered by the canonical facts.
Regression: examples/1117-diagnostics-value-const-as-type-rejected.sx (exit 1).
Issue-0064 regressions 1111-1116 and the 0115 aliases stay green. Gate: zig
build, zig build test, run_examples 352/0.
This commit is contained in:
18
examples/1117-diagnostics-value-const-as-type-rejected.sx
Normal file
18
examples/1117-diagnostics-value-const-as-type-rejected.sx
Normal file
@@ -0,0 +1,18 @@
|
||||
// A top-level VALUE constant name used in a type position is rejected. Without
|
||||
// the fix the unknown-type pass added every `const_decl` name to its declared-
|
||||
// type set, so a value const (`NotAType :: 123`) satisfied the check and the
|
||||
// type resolver's unknown-name fallback then fabricated an empty struct — the
|
||||
// program ran and printed `NotAType{}`. Now only consts whose value introduces a
|
||||
// type (declarations / type-expression aliases) count as type names.
|
||||
// Regression (issue 0068).
|
||||
// Expected: a clean "unknown type 'NotAType'" error at the annotation; exit 1.
|
||||
|
||||
#import "modules/std.sx";
|
||||
|
||||
NotAType :: 123;
|
||||
|
||||
main :: () -> s32 {
|
||||
v: NotAType = ---;
|
||||
print("value = {}\n", v);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,5 @@
|
||||
error: unknown type 'NotAType'
|
||||
--> examples/1117-diagnostics-value-const-as-type-rejected.sx:15:8
|
||||
|
|
||||
15 | v: NotAType = ---;
|
||||
| ^^^^^^^^
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user