Repository navigation
types: a callback that misses a closed arrow points at ->{e} - #181
Merged
Merged
Conversation
An extern callback arrow written without an effect variable is closed, so a
handler that does anything (an async { } block performs async) failed with
"effect mismatch: cannot unify Writer -> Async unit with Writer ->{io, async}
Async unit" under the whole call. The obvious repair, pasting the inferred
set into the extern, then rejects a handler that only awaits, because declared
effects are exact.
infer_apply_plain now hands an effect mismatch to closed_callback_hint, which
walks the declared callback and the argument arrow by arrow to the first
closed declared effect the argument's differs from, and reports it at the
argument:
`handle` performs {io, async}, but `serve` takes this callback as
`Writer -> Async unit`, which performs nothing; to accept a callback
whatever it does, give that arrow an effect variable in the extern that
declares it: `Reader -> Writer ->{e} Async unit`
A declared exact set says "which performs exactly {io, async}". A plain type
mismatch keeps its message. The cold-async e2e test, which had pasted in
`->{io, async}`, now uses `->{e}`. DESIGN §4 records the message.
Fixes #180
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.
Fixes #180.
Before, under the whole call:
After, on the argument:
How:
infer_apply_plainhands an effect mismatch toclosed_callback_hint. It walks the declared callback and the argument arrow by arrow to the first closed declared effect the argument's differs from, then reports at the argument with both effects and the declared type rewritten with->{e}on that arrow (show_with_effect_var). Diagnostics have no separate help line, so the guidance goes in the message, as theString.concatandList.concathints do.The pasted-set trap the issue warns about is covered too. Declared effects are exact, so
->{io, async}rejects a handler that only awaits, and that case now sayswhich performs exactly {io, async}and offers the same->{e}fix.Unchanged: a plain type mismatch (
serve 5 …) keepstype mismatch: expected Writer -> Async unit, found int. Lambdas (this function performs …), the pipe form (handle |> serve) and a callback in a later argument slot all get the new message.Also:
e2e_an_async_callback_handed_to_python_runsfrom #177 had pasted in->{io, async}, the exact mistake #180 describes. It now uses->{e}. DESIGN §4 records the message.Tests: the exact message and span for the issue's example, the exact-set case, and the unchanged type mismatch. Checked locally:
cargo fmt,cargo clippy --all-targets(clean),cargo test(every binary),docs/verify_lessons.py.