Type checker doesn't understand divergent early-exit patterns #134
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
refactor
rust
technical-debt
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
navicore/patch-seq#134
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The type checker rejects valid error-checking code in infinite loops because it doesn't understand divergent early-exit patterns.
Example
This pattern is rejected:
Error:
Analysis
The pattern
not if drop X-loop thenis an early-exit that:not)The type checker sees:
store-loopwhich never returns (divergent)These should be compatible because the
thenbranch diverges (never produces a value), so it's compatible with any continuation. In type theory, the bottom type (⊥) is a subtype of everything.Proposed Solution
The type checker should recognize that when an
ifbranch contains only a tail-call to a function with a compatible signature that never returns, it's a divergent branch and compatible with anyelsebranch.This pattern is common in:
Workaround
Currently we must drop the success flag without checking (
chan.receive drop), which triggers lint warnings and hides potential errors.Related
https://github.com/navicore/patch-seq/pull/137