From c2c2e1771bf9b747f38dc145b5201b45c579d465 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 26 Jul 2026 18:10:10 +0000 Subject: fix: close type-safety holes found by adversarial review; update docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review findings (all reproduced, then fixed and re-verified): - '^x' leaked as a raw address into any builtin context (s <- ^x printed the variable's bytes as a C string; NOT ^x, '&', and ^x = ^x compiled). Address-of is now rejected everywhere except a pointer-typed target. - A whole-array variable passed the nominal gate as a value of its ELEMENT type (s <- arrayOfSeason stored the raw data pointer; = on it emitted invalid IR). Whole arrays are now rejected as operands and as coercion sources; array parameters are unaffected. - Enum values smuggled into INTEGER through array subscripts and DECLARE bounds (a[Autumn], ARRAY[Spring:Winter]); both now go through emitCoercedExpr like every other INTEGER context. - An array DECLAREd inside an IF/WHILE/REPEAT/FOR body and used after the block was a wild-pointer write (constant bounds) or a verifier dump (runtime bounds). Arrays are now block-scoped: control-flow bodies snapshot and restore the ArrayTable, so escape is a clean compile error. - Duplicate parameter names silently shadowed (BYREF write-back defeated); now a parse error. Trailing comma in parameter lists accepted; now a parse error consistent with every other list. - A variable/array/parameter/function could reuse a TYPE name; reserved. - RETURN with a value inside a PROCEDURE was silently discarded (control did not return); now an error, as is a bare RETURN in a FUNCTION. - INPUT r.f mis-parsed into a three-error cascade; now one clear error. - Assigning to an enum constant now says so instead of 'Unknown variable'. Docs: ARCH/CONVENTIONS/EXTENDING/SUBSYSTEMS/PITFALLS rewritten for the TYPE system (ABI additions, nominal-typing invariants, admission-gate doors, array-parameter ABI, new recipes, new sharp edges); README features/TODO updated — random files are unblocked. Co-Authored-By: Claude Fable 5 --- lib/CodeGen/ArrayHandler.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'lib/CodeGen/ArrayHandler.cc') diff --git a/lib/CodeGen/ArrayHandler.cc b/lib/CodeGen/ArrayHandler.cc index c647d58..8b37b8f 100644 --- a/lib/CodeGen/ArrayHandler.cc +++ b/lib/CodeGen/ArrayHandler.cc @@ -88,15 +88,17 @@ void ArrayHandler::emitArrayDeclare(ArrayDeclareStmtAST *Stmt, CodeGen &CG) { CG.reportError("'%s' is an enum value and cannot be declared as an array", Name.c_str()); return; } + if (Types.resolve(Name)) { + CG.reportError("'%s' is a type name and cannot be declared as an array", Name.c_str()); + return; + } std::vector Lows; std::vector Highs; for (const auto &Pair : Stmt->getBounds()) { - Value *L = CG.emitExpr(Pair.first.get()); - Value *R = CG.emitExpr(Pair.second.get()); - L = CG.coerceValueToType(L, CG.resolveType("INTEGER")); - R = CG.coerceValueToType(R, CG.resolveType("INTEGER")); + Value *L = CG.emitCoercedExpr(Pair.first.get(), CG.resolveType("INTEGER")); + Value *R = CG.emitCoercedExpr(Pair.second.get(), CG.resolveType("INTEGER")); if (!L || !R) return; @@ -178,8 +180,7 @@ bool ArrayHandler::emitCheckedIndices(const std::string &Name, } for (size_t i = 0; i < IndexExprs.size(); ++i) { - Value *Idx = CG.emitExpr(IndexExprs[i].get()); - Idx = CG.coerceValueToType(Idx, CG.resolveType("INTEGER")); + Value *Idx = CG.emitCoercedExpr(IndexExprs[i].get(), CG.resolveType("INTEGER")); if (!Idx) return false; Out.push_back(Idx); -- cgit v1.3.1-4-g156e