Repository navigation
Description
Summary
Add object-safety test coverage for generic-method rejection on dyn traits. The implementation rejects generic trait methods for object use, but that rule needs explicit regression coverage.
Spec
§11.3 says dyn trait method calls require object-safe methods. Generic methods are not object-safe because a vtable slot cannot represent open-ended per-instantiation method bodies.
Current state
Sema.ensure_trait_object_safe rejects generic trait methods by checking method flags at src/SemaDecl.w:1865-1867. Parser.parse_trait_decl records the generic method flag when a trait method has type parameters at src/Parser.w:2588-2627. Existing object-safety tests cover shared and mutating receivers (test/spec/spec_ss11_3_object_safety.w:5-42) and separate compile-error tests cover Self in params/returns, but the requirements campaign found generic-method rejection untested.
Implementation plan
- Add a compile-error fixture with a trait containing
fn id[T](self: &Self, value: T) -> Tand a function accepting&dyn Trait. - Assert the current diagnostic substring
is generic, ortrait '<T>' is not object-safe: method '<m>' is genericif stable. - Add a positive adjacent test where the same trait without method type params can be used as
&dyn Trait. - If Object safety: vtable exclusion and Box[dyn] consuming-receiver shim (§11.3) #432 changes object-safety to per-method vtable exclusion, update the expected behavior deliberately: generic methods should either be excluded and uncallable or continue to reject dyn use, but the test must encode the chosen rule.
Test plan
Add:
test/compile_errors/err_dyn_trait_generic_method_not_object_safe.w- Optional
test/spec/spec_ss11_3_object_safety_generic_positive.wfor non-generic method dyn use if existing coverage is insufficient.
Acceptance criteria
- Generic trait methods have direct object-safety negative coverage.
- The test remains valid after Object safety: vtable exclusion and Box[dyn] consuming-receiver shim (§11.3) #432's vtable-exclusion work, with expected behavior updated explicitly if the rule changes.
with build && with build :fixpoint && with build :testpass.
Dependencies
#432 may change the exact dyn object-safety policy and diagnostic shape.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 11.3.1.9.
Activity
ehartford commentedon Jul 3, 2026
Covered by
test/compile_errors/err_object_safety_generic_method.w— a trait withfn id[T](self: &Self, value: T) -> Tused behind&dyn Containeris rejected withtrait 'Container' is not object-safe: method 'id' is generic(§11.3). Verified on HEAD; full gate green (native-compile-error-tests 681, native-spec-tests 206, GATES EXIT: 0).test: pin generic-method object-safety + comptime-with clause diagnos…