Skip to content

feat: generics multiple-bound conjunctions (ILO-386)#633

Merged
danieljohnmorris merged 1 commit into
feature/generic-return-type-subfrom
feature/generics-multibound
May 22, 2026
Merged

feat: generics multiple-bound conjunctions (ILO-386)#633
danieljohnmorris merged 1 commit into
feature/generic-return-type-subfrom
feature/generics-multibound

Conversation

@danieljohnmorris
Copy link
Copy Markdown
Collaborator

Summary

Changes

src/ast/mod.rs: type_params field changed from Vec<(String, Bound)> to Vec<(String, Vec<Bound>)> — each type variable carries a conjunction of bounds.

src/parser/mod.rs: After consuming the first bound name, loops consuming + + another bound ident to build the conjunction. No tokenizer changes needed — Token::Plus already existed.

src/verify.rs: type_bounds map now holds Vec<Bound>; call-site bound checker iterates all bounds in the conjunction and emits ILO-T044 for each unsatisfied one.

tests/regression_generics_multibound.rs: 10 regression tests covering:

  • Acceptance: n satisfies numeric+comparable
  • Rejection: t fails numeric in numeric+comparable
  • Rejection: b fails both bounds in numeric+text
  • Three-bound impossible conjunctions (numeric+comparable+text)
  • Order independence (comparable+numeric behaves same as numeric+comparable)
  • Regressions: single-bound and unbounded type vars still work

Test plan

  • cargo test --test regression_generics_multibound — 10/10 pass
  • cargo test --lib — 3342/3342 pass
  • Full integration test suite

Closes ILO-386

🤖 Generated with Claude Code

Extend bounded generics (ILO-61) to support conjunctions of bounds via
`+` syntax: `<a:numeric+comparable>` means `a` must satisfy ALL listed
bounds (intersection, not union).

Changes:
- ast: `type_params` changed from `Vec<(String, Bound)>` to
  `Vec<(String, Vec<Bound>)>` — each type variable carries a
  conjunction of bounds; an empty list or `[Any]` means unconstrained.
- parser: after consuming the first bound name, loop consuming `+`
  and another bound ident to build the conjunction vec.
- verify: `type_bounds` map now holds `Vec<Bound>`; call-site checker
  iterates all bounds in the conjunction and emits ILO-T044 for each
  unsatisfied one.
- tests: 10 regression tests covering acceptance (n for
  numeric+comparable), rejection (t fails numeric, b fails numeric+text),
  3-bound impossible conjunctions, and order independence.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@danieljohnmorris danieljohnmorris merged commit 4984d8d into feature/generic-return-type-sub May 22, 2026
@danieljohnmorris danieljohnmorris deleted the feature/generics-multibound branch May 22, 2026 01:23
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.

1 participant