fix: array params no longer get auto-const per ADR-006#987
fix: array params no longer get auto-const per ADR-006#987
Conversation
ADR-006 specifies that all params are pass-by-reference as mutable.
Scalar params correctly transpiled as mutable pointers, but array
params were incorrectly getting auto-const applied when unmodified.
This broke compatibility with C APIs expecting mutable pointers:
void handle(u8[8] data) {
global.process_data(data); // C API expects mutable uint8_t*
}
Generated: void handle(const uint8_t data[8]) - ERROR
Expected: void handle(uint8_t data[8]) - correct
Fix: Arrays now never get auto-const. Only explicit const from
source code (const u8[8] data) will add the const qualifier.
Changes:
- ParameterInputAdapter: Set isAutoConst=false for arrays
- Transpiler: Remove arrays from auto-const logic in headers
- Add unit test for new array auto-const behavior
- Update comment in auto-const-pointer.test.cnx
- Update affected test snapshots
Fixes #986
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
jlaustill
left a comment
There was a problem hiding this comment.
Review Summary
PR: #987 — fix: array params no longer get auto-const per ADR-006
Reviewed by: Claude (automated review)
Overview
Clean, well-scoped bug fix that correctly removes auto-const inference from array parameters. The change aligns with ADR-006's principle that all params are pass-by-reference and mutable. The fix addresses both code paths (CodeGenerator via ParameterInputAdapter and header generation via Transpiler.convertToHeaderSymbols), preventing const from being applied to array params that are only read — which broke compatibility with C APIs expecting mutable pointers.
Findings
| Severity | Count |
|---|---|
| Critical | 0 |
| Important | 1 |
| Moderate | 0 |
| Nit | 0 |
Key Issues
- [important] The
tests/const-params/auto-const-pointer.expected.hfile was NOT updated in this PR, but it containsarrayReadOnly(const uint8_t arr[4])which should now bearrayReadOnly(uint8_t arr[4])per the behavioral change. See inline comment.
What Looks Good
- Both code paths fixed: The
ParameterInputAdapter._buildArrayInputFromAST()andTranspiler.convertToHeaderSymbols()changes together eliminate all paths where arrays could get auto-const. The cross-reference agent confirmed no other paths exist. - Excellent regression test: The
fake_lib.c/.happroach directly exercises the real-world scenario (passing an array to a C API that mutates it), with execution validation via return codes. - Minimal, focused change: The actual logic changes are ~6 lines across 2 files, with the rest being consistent snapshot updates. No scope creep.
- Good comment hygiene: Updated the
auto-const-pointer.test.cnxcomments to explain the new behavior, and theParameterSignatureBuilder.test.tscomments clarify why existing builder tests still pass.
🤖 Automated review by Claude Code
| // Array parameter read-only | ||
| uint8_t arrayReadOnly(const uint8_t arr[4]) { | ||
| // Array parameter read-only - arrays never get auto-const per ADR-006 | ||
| // (arrays are mutable by default; use explicit const if needed) |
There was a problem hiding this comment.
[important] design: The .expected.c and .expected.cpp snapshots were correctly updated here to remove const from arrayReadOnly, but the corresponding auto-const-pointer.expected.h file was not updated in this PR.
On main, that file still contains:
uint8_t arrayReadOnly(const uint8_t arr[4]);Since Transpiler.convertToHeaderSymbols() no longer sets isAutoConst: true for array params, the generated header should now be:
uint8_t arrayReadOnly(uint8_t arr[4]);This is the only .expected.h file in the repo affected (I checked all others — none have const on array params in header prototypes). If the test framework compares .expected.h files, this would cause a test failure. If it doesn't, the file is still stale and misleading.
Fix: Update tests/const-params/auto-const-pointer.expected.h line 21:
| // (arrays are mutable by default; use explicit const if needed) | |
| uint8_t arrayReadOnly(uint8_t arr[4]); |



Summary
Fixes #986: Array parameters were incorrectly getting
constapplied when passed to C APIs expecting mutable pointers.Problem:
uint8_t*)constwhen not directly modified in the function bodyGenerated:
void handle(const uint8_t data[8])- compile errorExpected:
void handle(uint8_t data[8])- correctFix:
Arrays now never get auto-const. Only explicit const from source code (
const u8[8] data) adds the qualifier.Changes
ParameterInputAdapter: SetisAutoConst=falsefor all array paramsTranspiler: Remove arrays from auto-const logic in header generationbugs/issue-986-const-array-param/Test plan
🤖 Generated with Claude Code