Skip to content

Conversation

@purefunctor
Copy link
Owner

No description provided.

This refactors the error reporting in the checking crate to render local
types eagerly. This is a pre-requisite for creating a diagnostics crate,
which will be used for the LSP's error reporting and integration tests.
This introduces the significant_ranges function in diagnostics::context
to extract the significant ranges in a node. Annotations are attached to
InstanceDeclaration, not InstanceChain; this makes it impossible for the
naive Annotation-stripping approach to work, leading to confusing
offsets during diagnostic reporting.
This improves inference for do statements by using a unification
variable as a stand-in for the innermost expression when emulating
desugard bind/discard expressions. Inferring the pure_expression too
early causes the unification variables we created for the do statement
binders to be solved too eagerly; in the case of 215, the error becomes
associated to `pure "life"` rather than `add a b`.
purefunctor and others added 26 commits January 24, 2026 07:23
This adds a missing unification rule for Type::Variable, which relied on
an ID-based check before inline kinds were introduced.
This fixes an issue where `discard` is eagerly required when checking do
expressions, even on expressions that only ever use `bind`. This lazy
resolution is necessary as `bind` and `discard` are canonically defined
in separate modules, `Control.Bind` and `Control.Discard`.

In addition to lazy resolution, if `discard` cannot be resolved, the
compiler synthesises a type that would match most of its general usages,
outside of non-monadic definitions of `bind` and `discard`.
Extends the lazy discard pattern from d18813a to all rebindable
do/ado functions. Resolution and error reporting now only occurs
when the function is actually needed:

Do-notation:
- bind: only when <- statements exist
- discard: only when non-final discard statements exist (unchanged)

Ado-notation:
- 0 actions: only pure needed
- 1 action: only map needed
- 2+ actions: map + apply needed

When a needed function is missing, a constraint-free synthetic type
is used to allow type checking to continue with useful inference.
This improves error recovery and avoids spurious 'not in scope'
errors for unused functions.

Co-authored-by: Amp <[email protected]>
Amp-Thread-ID: https://ampcode.com/threads/T-019bffd6-adf2-777c-bfdb-dcc91b5b504f
- Rename synth_* to lookup_or_synthesise_* taking Option<Resolution>
- Use with_position() for allocation-free final-position checks
- Only synthesise bind/discard types for non-final actions
- Reduces unification variable count in do-blocks

Co-authored-by: Amp <[email protected]>
Amp-Thread-ID: https://ampcode.com/threads/T-019c00d9-1df4-778e-80f0-14a15fd7abf4g
This adds the InvalidFinalBind warning and InvalidFinalLet error to
inform the user that the final statement in a do expression is invalid.
For bind statements, the expression can be used to recover the type of
the do expression had it been a discard statement instead.

Co-authored-by: Amp <[email protected]>
Amp-Thread: https://ampcode.com/threads/T-019c00ee-da00-73df-b838-016a21109a08
An invalid kind for the function position in infer_surface_app_kind
prevented implicit type variable arguments from being bound onto the
environment. This was demonstrated by 251_lookup_implicit_panic which
triggers a panic on the use of the type variable `a` on the instance
declaration body.

This commit adds inference for the `argument_t`, returning the
elaborated type and an unknown kind for the application.
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.

2 participants