Skip to content

Report a capability used as a value in Flow terms, not as a clang error (#561) - #569

Merged
godofecht merged 2 commits into
mainfrom
capability-not-a-value
Aug 19, 2026
Merged

godofecht merged 2 commits into
mainfrom
capability-not-a-value

Conversation

@godofecht

@godofecht godofecht commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #561.

The defect

A capability is a handler, not a value. Naming one at a call site was reported badly in both modes.

Strict checking said nothing about capabilities:

✗ Undefined variable 'UnitCounter'
✗ No matching overload for function 'run' with arguments (i32)

--lenient got further and emitted C referencing a symbol nothing defines:

dyn.c:159:43: error: use of undeclared identifier 'UnitCounter'

This is the issue's option 1: reject it in the front end with a message naming the construct.

After

Both modes now report:

✗ Capability 'UnitCounter' is not a value and cannot be passed as an argument.
  Install it for the call instead: handle <Effect> with UnitCounter { ... }

and exit 1.

The one design decision

Keeping this fatal under --lenient needed a fatal_errors list on TypeCheckResult that lenient mode does not downgrade. --lenient means "compile anyway", which should not extend to emitting C that cannot build: the author gets a message about their own source instead of a clang error naming an identifier they never wrote. Ordinary undefined names are untouched and still warn under --lenient.

What is not changed

The declaration form still works. A function may declare a capability EffectName parameter and call operations on it. tests/unit/test_coverage_known_bugs.py::test_capability_parameter_method_call_type_checks_by_effect_signature covers that and still passes — an earlier attempt of mine rejected the declaration and that test correctly caught it. The gap is purely that there is no way to produce the value to pass, which is the issue's option 2 and remains open.

Docs

docs/effects-showcase.md said the parameter style was "rejected by the type checker", which was never true, and then described the lenient behaviour this PR changes. Rewritten to say what actually holds.

Verification

Check Result
pytest tests/ 1594 passed, 6 skipped
./flow test --tier2 --strict 687/687
ruff check src clean

Five new tests in tests/unit/test_capability_not_a_value.py cover the message, that it points at handle, that lenient keeps it fatal, that an ordinary undefined name is unaffected, and that capability parameters still type check.

…or (#561)

A capability is a handler, not a value. Naming one at a call site produced
"Undefined variable 'UnitCounter'" under strict checking, which does not
mention capabilities at all, and under --lenient it reached the backend and
emitted C referencing a symbol nothing defines:

    dyn.c:159:43: error: use of undeclared identifier 'UnitCounter'

Both now report:

    Capability 'UnitCounter' is not a value and cannot be passed as an
    argument. Install it for the call instead:
    handle <Effect> with UnitCounter { ... }

This needed a fatal_errors channel on TypeCheckResult that --lenient does not
downgrade. --lenient means "compile anyway", which should not extend to
emitting C that cannot build; the author gets a message about their own
source instead of a clang error naming an identifier they never wrote.
Ordinary undefined names are untouched and still warn under --lenient.

The declaration form is unaffected. A function may still declare a
`capability EffectName` parameter and call operations on it, which
tests/unit/test_coverage_known_bugs.py covers; there is simply no way to
produce the value to pass. The note in docs/effects-showcase.md said the
parameter style was "rejected by the type checker", which was never the case,
and described the lenient behaviour this commit changes.
@godofecht
godofecht merged commit 174ec26 into main Aug 19, 2026
20 checks passed
@godofecht
godofecht deleted the capability-not-a-value branch August 19, 2026 09:52
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.

capability E as a parameter type lowers to invalid C instead of a Flow diagnostic

1 participant