Skip to content

fix(validate): reject callbacks named ownership in ownership scope - #8

Merged
Sam Gammon (sgammon) merged 1 commit into
mainfrom
detail/bug-fix/fix-validate-reject-callbacks-named-ownership-in-o-469bbc
Oct 17, 2026
Merged

Sam Gammon (sgammon) merged 1 commit into
mainfrom
detail/bug-fix/fix-validate-reject-callbacks-named-ownership-in-o-469bbc

Conversation

@detail-app

@detail-app detail-app Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Detail bug report: View on Detail

Bug

When a seam module declares resources or borrows, the generator emits a top-level pub mod ownership { ... } in seam.rs. OwnershipValidator reserved the name ownership against opaque types and structs to prevent collisions, but callbacks were not checked. Since RustFfi emits each callback as a top-level pub type <name> = Option<...>, a callback named ownership passed validation and produced both pub type ownership = ... and pub mod ownership { ... } in the same file — a Rust E0428 compile error (the name 'ownership' is defined multiple times). Generation succeeded with exit 0, pushing the failure downstream to the Rust compiler with no validation diagnostic.

Closes #6

Fix

Extended the reservation check in OwnershipValidator.validate to also reject callbacks named ownership:

require(
    !m.opaqueTypes().contains("ownership")
        && m.structs().stream().noneMatch(s -> s.name().equals("ownership"))
        && m.callbacks().stream().noneMatch(c -> c.name().equals("ownership")),
    "ownership is reserved when wrappers are generated");

This mirrors the existing opaque-type and struct reservation, using the same error message. The guard only applies when resources or borrows are present (i.e., when the ownership module is generated), so bare modules without ownership wrappers are unaffected.

Testing

  • Unit tests (mvn -B verify): 156 tests pass, 0 failures. JaCoCo coverage gate (85% line / 70% branch) met. Added two tests to OwnershipTest:
    • rejectsOwnershipNameReservedForWrappers — parameterized over opaque types, structs, and callbacks named ownership; verifies all three are rejected in both relaxed and strict modes with the correct message.
    • reservedNameGuardAllowsCallbackOwnershipInBareModules — verifies a callback named ownership is allowed when a module has no resources/borrows, and the generated seam.rs contains the type alias but no pub mod ownership.
  • CLI end-to-end: Appending callback ownership return=void to examples/ownership.seam and running both validate and generate now fails with exit 2 and the message "ownership is reserved when wrappers are generated" (previously: exit 0, producing uncompilable Rust).
  • Rust compilation: Installed rustc 1.85.1 and compiled the generated seam.rs from the unmodified examples/ownership.seam and from a variant with a callback named Sink — both compile cleanly with no E0428. The bug case (callback named ownership) is now rejected at validation time, so no Rust output is produced.

Automatic Fixes PRs can be configured here.

@codecov

codecov Bot commented Oct 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.04%. Comparing base (c7d278e) to head (a5e3a97).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff              @@
##               main       #8      +/-   ##
============================================
+ Coverage     93.77%   94.04%   +0.26%     
- Complexity      656      663       +7     
============================================
  Files            18       18              
  Lines          1895     1896       +1     
  Branches        391      391              
============================================
+ Hits           1777     1783       +6     
+ Misses           37       36       -1     
+ Partials         81       77       -4     
Flag Coverage Δ
jvm 94.04% <100.00%> (+0.26%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@sgammon
Sam Gammon (sgammon) merged commit 7036048 into main Oct 17, 2026
8 of 10 checks passed
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.

[Detail Bug] Rust FFI: callback named ownership breaks generated Rust compilation

1 participant