Bug
E0872 (writing false/0 to a write-1 register bit) sees a const bool only when the name is written bare. Written this., global. or Scope., the same false const slips past the check. The this. form crashes code generation, and the other two compile with exit 0.
Repro, with tests/adr-004/register-declarations.cnx alongside (HW.SET is w1s):
#include "register-declarations.cnx"
const bool OFF <- false;
scope Board {
const bool OFF_HERE <- false;
public const bool OFF_PUB <- false;
public void go() {
global.HW.SET[1] <- OFF; // error[E0872]: Cannot assign false to write-only register bit
global.HW.SET[2] <- this.OFF_HERE; // Code generation failed: Internal: a write-1 register bit takes a non-zero value -- E0872 rejects 'false' ... in pass 2.1, before this runs
global.HW.SET[3] <- global.OFF; // exit 0
global.HW.SET[5] <- global.Board.OFF_PUB; // exit 0
}
}
I ran one row per file with npx tsx src/cli/index.ts <file> --target host, on both origin/main 0cd9699 and #1990's branch, and got the same results on each. The rows that exit 0 emit:
HW__SET = ((uint32_t)(OFF ? 1U : 0U) << 3);
HW__SET = ((uint32_t)(Board__OFF_PUB ? 1U : 0U) << 5);
Cause
RegisterAccessAnalyzer.isZero first asks ConstantExpression.valueAt, which has no value for a bool const. It then falls back to isFalseConst, which accepts only /^[A-Za-z_]\w*$/ and compares the declaration's initialValue text with "false". A qualified name never reaches the binder.
A second place in code generation also decides "is this write a zero". It recognizes this.OFF_HERE but not global.OFF. So the analyzer and the generator disagree with each other as well as with the bare spelling. The issue is the same shape as #1268 and #1995.
Found by
Re-checking #1990 against the c-next way skill. E0872 wasn't one of the eight error codes in #1268's bare-vs-qualified table.
Written by Devin
Bug
E0872 (writing
false/0 to a write-1 register bit) sees aconst boolonly when the name is written bare. Writtenthis.,global.orScope., the samefalseconst slips past the check. Thethis.form crashes code generation, and the other two compile with exit 0.Repro, with
tests/adr-004/register-declarations.cnxalongside (HW.SETisw1s):I ran one row per file with
npx tsx src/cli/index.ts <file> --target host, on bothorigin/main0cd9699 and #1990's branch, and got the same results on each. The rows that exit 0 emit:Cause
RegisterAccessAnalyzer.isZerofirst asksConstantExpression.valueAt, which has no value for aboolconst. It then falls back toisFalseConst, which accepts only/^[A-Za-z_]\w*$/and compares the declaration'sinitialValuetext with"false". A qualified name never reaches the binder.A second place in code generation also decides "is this write a zero". It recognizes
this.OFF_HEREbut notglobal.OFF. So the analyzer and the generator disagree with each other as well as with the bare spelling. The issue is the same shape as #1268 and #1995.Found by
Re-checking #1990 against the c-next way skill. E0872 wasn't one of the eight error codes in #1268's bare-vs-qualified table.
Written by Devin