Skip to content

Tests: operator dispatch coverage (§11) #514

Closed

Description

@ehartford

Summary

Add missing operator-dispatch regression tests for already-working binary operators. The requirements campaign probed *, /, !=, <, <=, >, and >=, but those cases are not covered by durable tests.

Spec

§11.7 maps fixed operator method names: mul, div, ne, lt, le, gt, and ge, and requires static resolution with exactly one applicable implementation.

Current state

Sema maps binary operators to method names at src/SemaCheck.w:3703-3715, selects left/right candidates at src/SemaCheck.w:3767-3800, and routes comparison/arithmetic operators through that mechanism at src/SemaCheck.w:4109-4170. Existing tests cover add/sub/right-side dispatch (test/spec/spec_ss11_7_operator_one_impl_rule.w:6-34) and matmul (test/spec/spec_ss11_7_multi_index_and_dispatch.w:108-115), but not all probed operators. Negative tests already cover ambiguity and inapplicable implementations (test/compile_errors/err_operator_ambiguous_two_impls.w, test/compile_errors/err_operator_inapplicable_impl.w).

Implementation plan

  1. Add a single spec test file with a small user type implementing mul, div, ne, lt, le, gt, and ge.
  2. Exercise both value and borrowed receiver styles where currently supported, but avoid relying on Prelude operator traits Add/Sub/Mul/Div/MatMul/Neg (§11.7) #469's optional trait declarations.
  3. Include one chained expression where safe, and keep comparison results bool.
  4. Add a negative test for a comparison operator method returning non-bool if existing err_operator_compare_non_bool.w is not sufficient.
  5. Do not change operator resolution unless the new tests expose a real bug.

Test plan

Add test/spec/spec_ss11_7_operator_dispatch_more.w:

  • a * b calls mul
  • a / b calls div
  • a != b calls ne
  • <, <=, >, >= call the matching methods

Verify/extend:

  • test/compile_errors/err_operator_compare_non_bool.w
  • test/compile_errors/err_operator_ambiguous_two_impls.w

Acceptance criteria

  • All requirement IDs listed in the original issue have positive operator-dispatch coverage.
  • Comparison method return type remains enforced as bool.
  • No behavior changes are made unless tests reveal a defect.
  • with build && with build :fixpoint && with build :test pass.

Dependencies

#464 adds unary neg dispatch tests. #469 adds optional prelude trait declarations.

Traceability

From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 11.7.1.27, 11.7.1.28, 11.7.1.32, 11.7.1.33, 11.7.1.34, 11.7.1.35, 11.7.1.36.

Activity

  1. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    Closing — operator dispatch for mul/div and the full comparison family (ne/lt/le/gt/ge) pinned by spec_ss11_operator_dispatch_full (ec03406). §11.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions