Skip to content

fix(codegen): emit operator==/operator<< for unions so structs containing unions compile - #93

Open
devin-ai-integration[bot] wants to merge 1 commit into
developmentfrom
devin/union-struct-codegen-fix
Open

fix(codegen): emit operator==/operator<< for unions so structs containing unions compile#93
devin-ai-integration[bot] wants to merge 1 commit into
developmentfrom
devin/union-struct-codegen-fix

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Fixes #92.

  • generateUnionType now emits operator== and operator!= using raw byte comparison over iec_byte_size, plus a test-only operator<< fallback so generated C++ headers compile when a STRUCT contains a UNION member.
  • This unblocks CODESYS SysSocket types such as SOCKADDRESS, whose sin_addr field is the INADDR union.
  • Added unit-test assertions in tests/backend/type-codegen.test.ts and a new tests/st-validation/data_types/union_in_struct.st + test_union_in_struct.st end-to-end fixture that exercises a SOCKADDRESS-style struct with an embedded union.

Checklist

  • Tests added or updated for the changed behavior.
  • npm run typecheck and npx eslint src/ --quiet pass.
  • npm test passes.
  • Documentation updated (IEC_COMPLIANCE.md, CODESYS_CLAIMS_LEDGER.md, README.md, etc.) if the change affects any behavior or claim covered by those docs.

Link to Devin session: https://app.devin.ai/sessions/8240483b7529498a8a4d3181be8fbe66
Requested by: @wattzor

…ning unions compile

- generateUnionType now emits operator==, operator!=, and a test-only
  operator<< so generated C++ headers compile when a STRUCT contains a UNION.
- Add unit-test assertions and an end-to-end st-validation fixture for a
  SOCKADDRESS-style struct that embeds an INADDR union.

Co-Authored-By: Simon Atti <wattimedia@gmail.com>
@wattzor wattzor self-assigned this Aug 9, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration

Copy link
Copy Markdown
Author

Test report: union-in-struct codegen fix

I verified the PR end-to-end on the devin/union-struct-codegen-fix branch.

End-to-end CLI proof

The new SOCKADDRESS/INADDR fixture compiles, its generated C++ operators build, the test binary passes all assertions, and strucpp --build links a runnable REPL binary.

node dist/node/cli.js tests/st-validation/data_types/union_in_struct.st \
  --test tests/st-validation/data_types/test_union_in_struct.st

CLI --test pass

node dist/node/cli.js tests/st-validation/data_types/union_in_struct.st \
  -o /tmp/sockaddr_build/ --build

CLI --build binary

Generated operators

generated.hpp now emits operator==, operator!=, and a test-only operator<< for both the INADDR union and the SOCKADDRESS struct:

Generated operators

Static checks & coverage

  • npm run typecheck
  • npm run lint ✅ (exit 0; 0 errors, 605 pre-existing warnings)
  • npm test ✅ (128 files / 2343 tests passed)
  • npm run test:coverage ✅ — global branches 85.22% (threshold 75%)
  • npx vitest run tests/backend/type-codegen.test.ts ✅ (15/15, including the new operator assertions)

Notes

  • src/backend/type-codegen.ts branch coverage is 66.2% (below 75% file-level) but the overall branch gate is still met.
  • npm run lint has many pre-existing warnings; the changed file adds 4 warnings and no errors.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UNION type lacks operator==/to_display_string, breaks any STRUCT containing a union

1 participant