Repository navigation
fix(validate): reject callbacks named ownership in ownership scope - #8
Merged
Sam Gammon (sgammon) merged 1 commit intoOct 17, 2026
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Detail bug report: View on Detail
Bug
When a seam module declares resources or borrows, the generator emits a top-level
pub mod ownership { ... }inseam.rs.OwnershipValidatorreserved the nameownershipagainst opaque types and structs to prevent collisions, but callbacks were not checked. SinceRustFfiemits each callback as a top-levelpub type <name> = Option<...>, a callback namedownershippassed validation and produced bothpub type ownership = ...andpub 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.validateto also reject callbacks namedownership: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
mvn -B verify): 156 tests pass, 0 failures. JaCoCo coverage gate (85% line / 70% branch) met. Added two tests toOwnershipTest:rejectsOwnershipNameReservedForWrappers— parameterized over opaque types, structs, and callbacks namedownership; verifies all three are rejected in both relaxed and strict modes with the correct message.reservedNameGuardAllowsCallbackOwnershipInBareModules— verifies a callback namedownershipis allowed when a module has no resources/borrows, and the generatedseam.rscontains the type alias but nopub mod ownership.callback ownership return=voidtoexamples/ownership.seamand running bothvalidateandgeneratenow fails with exit 2 and the message"ownership is reserved when wrappers are generated"(previously: exit 0, producing uncompilable Rust).rustc1.85.1 and compiled the generatedseam.rsfrom the unmodifiedexamples/ownership.seamand from a variant with a callback namedSink— both compile cleanly with no E0428. The bug case (callback namedownership) is now rejected at validation time, so no Rust output is produced.Automatic Fixes PRs can be configured here.