Skip to content

E0872 misses a this./global./Scope.-qualified false const (this. crashes codegen) #2008

Description

@devin-ai-integration

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority: mediumMedium priority - important but not blockingvalidation-bugMissing compile-time validation

    Projects

    • Status
      Grooming

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions