Skip to main content

Error

Enum Error 

Source
pub enum Error {
Show 63 variants ExportNotFound(Name, ExportType, NodeSpan), ExportedValueNotAnnotated(Name, NodeSpan, NodeSpan), EnvironmentErrors(Vec<EnvError>), InfixReferenceInvalidValue(Name, Name, NodeSpan), AmbiguousOperatorPrecedence(AmbiguousOperator, AmbiguousOperator, NodeSpan), BindingPatternsInvalidLen(NodeSpan), NoBindings(NodeSpan), VariableNotFound(QualName, NodeSpan, Option<Name>), AmbiguousVariables(Name, Vec<(ModuleName, Option<SourceSpan>, ImportOrigin)>, NodeSpan), VariantNotFound(QualName, NodeSpan, Option<Name>), AmbiguousVariants(Name, Vec<(ModuleName, Option<SourceSpan>, ImportOrigin)>, NodeSpan), InvalidTupleSize(usize), MultipleBindingsUnsupported(Name, NodeSpan), InvalidClassHead(NodeSpan), ClassNameTaken(Name, NameTakenBy, NodeSpan, NodeSpan), ClassNotFound(Name, NodeSpan), ConstraintNotOnVariable(NodeSpan), ConstraintVariableUnbound(Name, NodeSpan), ConstraintVariableNotInType(Name, NodeSpan), MemberConstrained(Name, NodeSpan), MemberUnsafe(Name, NodeSpan), MemberMissesClassVariable(Name, Name, Name, NodeSpan), MemberDeclaredTwice(Name, NodeSpan, NodeSpan), MemberNameTaken(Name, Name, Option<Name>, NodeSpan, NodeSpan), MemberExposedAlone(Name, Name, NodeSpan), ClassExposedWithConstructors(Name, NodeSpan), InvalidInstanceHead(InstanceHeadProblem, NodeSpan), InstanceBindingNotMember(Name, Name, NodeSpan), InstanceMemberMissing(Name, Name, NodeSpan), InstanceMemberBoundTwice(Name, NodeSpan, NodeSpan), OrphanInstance(Box<InstanceName>, NodeSpan), DuplicateInstance(Box<InstanceName>, NodeSpan, DeclarationSite), MissingSuperclassInstance(Box<InstanceName>, QualName, NodeSpan), DerivationForNonMember(Name, Name, NodeSpan), DerivationRepeated(Name, NodeSpan, NodeSpan), DerivationSignature(Name, DerivationSignatureProblem, NodeSpan, NodeSpan), DerivationBindingMissing(Name, Name, NodeSpan), DerivationBindingUnexpected(Name, Name, Vec<Name>, NodeSpan), DerivationBindingRepeated(Name, Name, NodeSpan, NodeSpan), DerivationBindingTakesTooMany(Name, Name, usize, NodeSpan), DerivationIncomplete(Name, Vec<Name>, NodeSpan), DerivedInstanceNotDerivable(Name, NodeSpan), DerivedInstanceNoShape(DerivedShapeProblem, NodeSpan), DerivedInstanceRequires(Box<DerivedRequirement>, NodeSpan), DerivedInstanceContextTooNarrow(Box<DerivedContextGap>, NodeSpan, NodeSpan), TypeArityMismatch(Name, usize, usize, NodeSpan), TypeNotFound(Name, NodeSpan), InvalidVariant(InvalidVariantKind, NodeSpan), InvalidScalarDeclaration(QualName, NodeSpan), InvalidConstraint(InvalidConstraintKind, NodeSpan), RepeatedLabel(Name, RecordForm, NodeSpan, NodeSpan), InfixDeclared(Name, NodeSpan), TypeDeclared(Name, NodeSpan), ClassDeclared(NodeSpan), InstanceDeclared(NodeSpan), NoTypeInBinding(Name, NodeSpan), UnsafeOutsideFacade(Name, NodeSpan), FacadeTypeNotAdmitted(Name, FacadeRejectedKind, NodeSpan), FacadeResultNotEffect(Name, NodeSpan), FacadeTaskMisplaced(Name, NodeSpan), FacadeConstrained(Name, NodeSpan), SelfDependency(Vec<CycleMember>), Many(Vec<Error>),
}
Expand description

Everything canonicalization can reject.

§Why only some variants carry a span

A variant carries a [NodeSpan] when its construction site has one in hand — it is looking at a parser::Import, parser::Infix, parser::UnionType, parser::Function or parser::Exposed, all of which the grammar gives a span. Those are the variants a diagnostic can put a caret under, and today that is every variant below except three: the two group variants, EnvironmentErrors and Many, have no position of their own and flatten their members’ labels instead; and InvalidTupleSize carries none for an unrelated reason — see its own doc comment. Writing NodeSpan::none() into a variant that lacks a real position would say “this error has a position we happen not to know”, which is a lie; leaving the field off says “this error has nowhere to point”, which is true, and the reporter renders it as message-plus-notes with no caret.

Variants§

§

ExportNotFound(Name, ExportType, NodeSpan)

A name in the module … exposing (…) header that nothing in the module declares, and where that name was written (ERR-9).

§

ExportedValueNotAnnotated(Name, NodeSpan, NodeSpan)

A value exposed by this module — named explicitly in its exposing list, or implicitly by exposing (..) — whose declaration carries no type annotation (SPEC-5: an exposed declaration must be annotated).

The first [NodeSpan] is where the exposing list names it — a real position for an explicit list, NodeSpan::none() for exposing (..), which names nothing individually and so has no per-value span to point at (parser::Exposing::Open carries none at all). The second is the declaration’s own span, always real: labels() falls back to it as the primary label when the first is absent, rather than pointing nowhere.

§

EnvironmentErrors(Vec<EnvError>)

§

InfixReferenceInvalidValue(Name, Name, NodeSpan)

(infix, function), and where the infix declaration was written

§

AmbiguousOperatorPrecedence(AmbiguousOperator, AmbiguousOperator, NodeSpan)

Infix re-association (reassociate_infix_chain) found two adjacent operators of equal precedence that do not agree how to group: the left one, the right one, and the ambiguous pair’s own span — from the left operator through the right one.

Three shapes reach this, and PhaseError::message says which: left.name == right.name is one infix non operator chained with itself (a == b == c); either side being infix non against a different operator is a non-associative operator that does not chain at all (a < b > c); and a left against a right is the genuine disagreement about which side groups first (a << b >> c).

§

BindingPatternsInvalidLen(NodeSpan)

§

NoBindings(NodeSpan)

A declaration with a type annotation and no body, and where the annotation was written — which is the only part of it there is to point at.

§

VariableNotFound(QualName, NodeSpan, Option<Name>)

A name used as a value that nothing in scope declares, where it was written — the identifier alone, not the declaration around it — and, when one name in scope is a close enough typo-distance match, a suggestion for what was meant (ERR-7).

§

AmbiguousVariables(Name, Vec<(ModuleName, Option<SourceSpan>, ImportOrigin)>, NodeSpan)

A name exposed unqualified by more than one imported module, and where it was used. Each candidate module is paired with where the name is declared there — Some when that module’s Interface knows both its file and the declaration’s span, None for a hand-built interface (a test) or one built before its module’s file was known (ERR-5) — and with whether that import was written by the module under check or supplied by the default import list, which a default entry participates in exactly as a written import does (SPEC-32/DEC-15); the note calls out a default contributor as implicit.

§

VariantNotFound(QualName, NodeSpan, Option<Name>)

A constructor used in an expression or a pattern that nothing in scope declares, where it was written, and an optional “did you mean …?” suggestion (ERR-7).

§

AmbiguousVariants(Name, Vec<(ModuleName, Option<SourceSpan>, ImportOrigin)>, NodeSpan)

Nothing constructs this today — Environment::find_type_constructor returns at most one constructor per name, so it has no way to report an ambiguity. It is the designated rejection path once it can, and carries the span the construction site would have, alongside each candidate’s declaration location — see Error::AmbiguousVariables.

§

InvalidTupleSize(usize)

A tuple type, pattern or expression had a size other than 2 or 3 (the only sizes the language supports).

Nothing constructs this today, and it is kept deliberately. Both ASTs now hold their tuples in [Tuple], which cannot represent another arity, and the grammar has one production per arity — so a bad tuple is a parse error and never reaches canonicalization. This variant is the designated rejection path should a future source of tuples (a REPL, a desugaring pass) build one from a list.

§

MultipleBindingsUnsupported(Name, NodeSpan)

A function was declared with multiple bindings (multi-clause definitions), which the compiler does not support yet.

§

InvalidClassHead(NodeSpan)

A class head that is not an uppercase name applied to exactly one type variable, and where the head was written, context excluded.

§

ClassNameTaken(Name, NameTakenBy, NodeSpan, NodeSpan)

A class declared where a type or an earlier class of the module already has its name, the two sharing one namespace: the name, which kind of declaration had it first, the class’s head line and the other declaration’s.

§

ClassNotFound(Name, NodeSpan)

A class name — a superclass, an instance’s class, a constraint in an instance’s or an annotation’s context — that nothing in scope declares: the name as written, and the constraint or the instance head it was written in.

§

ConstraintNotOnVariable(NodeSpan)

A constraint in a class head, an instance’s context or an annotation’s context whose argument is not one type variable, and the constraint’s span.

§

ConstraintVariableUnbound(Name, NodeSpan)

A constraint in a class head or an instance’s context on a type variable the head does not bind: the variable, and where it was written.

§

ConstraintVariableNotInType(Name, NodeSpan)

A constraint in an annotation’s context on a type variable the annotation’s type does not mention, so no caller could say which type it meant: the variable, and where it was written.

§

MemberConstrained(Name, NodeSpan)

A member signature written with a context of its own: the member, and the context’s span. A member signature carries no constraint.

§

MemberUnsafe(Name, NodeSpan)

A member signature marked unsafe, which only a facade signature may be: the member, and the signature’s span, which starts at the word.

§

MemberMissesClassVariable(Name, Name, Name, NodeSpan)

A member signature that never mentions the class variable, so no use of it could say which instance it meant: the member, the class, the class variable, and the signature’s span.

§

MemberDeclaredTwice(Name, NodeSpan, NodeSpan)

Two member signatures of one name in one class: the name, the second signature’s span and the first’s.

§

MemberNameTaken(Name, Name, Option<Name>, NodeSpan, NodeSpan)

A member whose name another value of the module already has — a top-level declaration, or a member of another of its classes. A member is a top-level value of the module declaring its class. Carries the member, its class, the other class when the other is a member, the member’s signature span and the other declaration’s.

§

MemberExposedAlone(Name, Name, NodeSpan)

A member named on its own in its module’s exposing list, where it is exposed with its class or not at all: the member, its class, and the entry’s span.

§

ClassExposedWithConstructors(Name, NodeSpan)

Name(..) in a module’s exposing list naming one of its classes, which has no constructors: the class, and the entry’s span.

§

InvalidInstanceHead(InstanceHeadProblem, NodeSpan)

An instance head that is not one of the forms a head may take: what is wrong with it, and the span of the part that is.

§

InstanceBindingNotMember(Name, Name, NodeSpan)

An instance binding that names no member of the class: the binding’s name, the class, and the binding’s span.

§

InstanceMemberMissing(Name, Name, NodeSpan)

A member of the class no binding of the instance defines: the member, the class, and the instance’s head line.

§

InstanceMemberBoundTwice(Name, NodeSpan, NodeSpan)

A member an instance binds twice: the member, the second binding’s span and the first’s.

§

OrphanInstance(Box<InstanceName>, NodeSpan)

An instance declared in a module that declares neither its class nor its head’s type (the orphan rule): the instance’s class and head, and its head line. The class and a declared head type each carry the module that declares them, which the message names.

§

DuplicateInstance(Box<InstanceName>, NodeSpan, DeclarationSite)

A second instance of one class for one head name: that class and head, the second instance’s head line, and where the first was declared.

§

MissingSuperclassInstance(Box<InstanceName>, QualName, NodeSpan)

An instance of a class with a superclass, with no instance of the superclass for the same head name in scope: the instance’s class and head, the superclass, and the instance’s head line.

§

DerivationForNonMember(Name, Name, NodeSpan)

A derived in a class body for a name the class does not declare as a member: the name as written, the class, and where derived name was written.

§

DerivationRepeated(Name, NodeSpan, NodeSpan)

A second derived for a member that has one: the member, the second derivation’s span and the first’s. A member has at most one.

§

DerivationSignature(Name, DerivationSignatureProblem, NodeSpan, NodeSpan)

A derivation for a member whose signature cannot carry one: the member, what is wrong with the signature, where derived member was written and where the member’s signature was.

§

DerivationBindingMissing(Name, Name, NodeSpan)

A derivation without a binding its member’s signature calls for: the binding, the member, and where derived member was written.

§

DerivationBindingUnexpected(Name, Name, Vec<Name>, NodeSpan)

A binding in a derivation that its member’s signature does not call for: the binding, the member, the bindings the derivation takes, and the binding’s span.

§

DerivationBindingRepeated(Name, Name, NodeSpan, NodeSpan)

A binding written twice in one derivation: the binding, the member, the second one’s span and the first’s.

§

DerivationBindingTakesTooMany(Name, Name, usize, NodeSpan)

A binding in a derivation written with more parameters than the walk supplies it: the binding, the member, how many parameters it may take, and the binding’s span. The compiler’s limit rather than the language’s: canonical code has no lambda to place such a binding with, and LANG-87 is the ticket.

§

DerivationIncomplete(Name, Vec<Name>, NodeSpan)

A class that derives some of its members and not the rest: the class, the members left out, and the class’s head line.

§

DerivedInstanceNotDerivable(Name, NodeSpan)

An instance asking to be derived for a class that is not derivable — one whose members do not all carry a derivation: the class, and the word derived.

§

DerivedInstanceNoShape(DerivedShapeProblem, NodeSpan)

A derived instance for a type with no shape for a walk to read: what is wrong, and the word derived.

§

DerivedInstanceRequires(Box<DerivedRequirement>, NodeSpan)

A derived instance for a type holding an argument with no instance of the class: which argument, and the word derived.

§

DerivedInstanceContextTooNarrow(Box<DerivedContextGap>, NodeSpan, NodeSpan)

A context written on a derived instance that does not provide a constraint the type’s arguments need: which constraint, the written context’s span and the word derived.

§

TypeArityMismatch(Name, usize, usize, NodeSpan)

A type name applied to the wrong number of arguments: the name, its declaration’s own arity, the number of arguments actually written, and tpe.span — the whole application, so the caret covers every argument along with the name (BUG-17).

§

TypeNotFound(Name, NodeSpan)

A type name written in a type expression that nothing in scope declares: the name exactly as it was written, and tpe.span — the application, so the caret covers the name along with whatever it was applied to.

The declarations of the module under check are in scope here as much as its imports are, so this is a name neither half offers. Only the TypeKind::Unqualified arm of Type::from_parser_type raises it: a type variable arrives as TypeKind::Variable and is bound by the annotation it appears in, so it resolves through nothing and cannot reach here.

§

InvalidVariant(InvalidVariantKind, NodeSpan)

Something other than a constructor name and its arguments written in a type declaration’s variant position: what was written there, and that variant’s own span rather than the declaration’s, so the caret sits under the offending variant alone (BUG-18).

§

InvalidScalarDeclaration(QualName, NodeSpan)

An opaque scalar’s type declaration — Basics.Int, Basics.Float, Char.Char or String.String — whose body is something other than exactly its own name with no arguments (LANG-59, DEC-15 decision 2). Nothing in the language constructs or inspects a value of one of these four, so the declaration exists to be read rather than built from, and a body naming anything else — a different type, extra variants, arguments — would describe a representation the language does not have.

Carries the declaration’s qualified name and the whole declaration’s span (tpe.span), the same position Error::InvalidVariant would rather than a per-variant one — the check runs on the shape of the whole variant list, not on one variant that is wrong among otherwise-good ones.

§

InvalidConstraint(InvalidConstraintKind, NodeSpan)

Something other than a constraint written in front of an annotation’s =>: what was written, and that piece’s own span — one constraint of a parenthesised list rather than the whole context, so the caret sits under the part that is wrong.

The grammar parses each element of a context as a type (see parser::Context), so every shape a type can take arrives here; validate_context is what narrows each one to a constraint.

§

RepeatedLabel(Name, RecordForm, NodeSpan, NodeSpan)

A label given to two fields of one record type, record, update or record pattern: the label, which of the four forms it was found in, where the repeat was written and where the first field with that label was. Both spans are the label’s alone, so the primary caret sits under the repeat and a secondary one under the first.

Records makes it an error in all four, once where it states it for a record type, a record, an update and a record pattern: a record type is a set of fields, a record and an update say each field’s value once, and a record pattern says once what each field it names is matched against. One error per repeat, each naming the first, so a label written three times is two.

§

InfixDeclared(Name, NodeSpan)

§

TypeDeclared(Name, NodeSpan)

§

ClassDeclared(NodeSpan)

A class declaration in a module foreign facade, which holds signatures only: the class’s head line.

§

InstanceDeclared(NodeSpan)

An instance declaration in a module foreign facade: its head line.

§

NoTypeInBinding(Name, NodeSpan)

§

UnsafeOutsideFacade(Name, NodeSpan)

An annotation outside a module foreign facade was marked unsafe: the name it annotates, and the annotation’s span — which the grammar takes from the modifier, so the caret starts on the word itself.

unsafe asserts something about the companion behind a facade signature (LANG-53, DEC-12). There is no companion behind an ordinary declaration for it to be a claim about, and accepting the word there would make it mean nothing in half the places it can be written.

§

FacadeTypeNotAdmitted(Name, FacadeRejectedKind, NodeSpan)

A module foreign facade signature naming a type variable or a function type, in a parameter or in the result, once the arrows separating a facade’s own parameters are stripped (docs/spec/interop.md#what-a-facade-signature-may-not-name): the value’s name, which form was found, and function.annotation_span.

The span is the whole annotation rather than the offending piece of it, because a canonical Type carries no span of its own — see Type::from_parser_type’s doc comment — and the annotation is the finest caret available without first teaching that conversion to keep per-node spans.

§

FacadeResultNotEffect(Name, NodeSpan)

An unmarked module foreign facade signature whose result type — the last piece facade_signature_pieces returns, once check_facade_admitted_type has already accepted it — is not exactly Task (Result Failure a): the value’s name, and function.annotation_span.

An effectful facade settles the shape: a facade declares an effect unless its signature is marked unsafe, and an effectful facade’s result type must be exactly Task (Result Failure a). Never raised for a signature function.marked_unsafe — unsafe removes the requirement, not the boundary check itself.

The span is the whole annotation rather than the offending piece of it, for the same reason Error::FacadeTypeNotAdmitted uses it — a canonical Type carries no span of its own.

§

FacadeTaskMisplaced(Name, NodeSpan)

Task named anywhere in a module foreign facade signature other than the whole of an unmarked facade’s result: the value’s name, and function.annotation_span.

An effectful facade confines Task to that one position — never as an argument, and never nested inside another type, whether or not the signature is marked unsafe. Task is recognised by the qualified name of its declaration (is_task_declaration) and never by spelling, so a module’s own type named Task is an ordinary union here, not this.

The span is the whole annotation, as Error::FacadeTypeNotAdmitted’s is.

§

FacadeConstrained(Name, NodeSpan)

A module foreign facade signature written with a constraint context: the value’s name, and the context’s span.

A facade is monomorphic — its signature names the types the code behind it really handles (Type classes, DEC-2 decision 6) — and a constrained function is specialised per instance out of a body a facade does not have. Reported whatever the context’s shape, a well-formed one included.

§

SelfDependency(Vec<CycleMember>)

A parameterless binding that depends on itself — evaluation semantics: such a binding is evaluated once, before the program runs, after everything it depends on, and a cycle through it describes no such order. Depends on is transitive mention: the declarations its body mentions, the ones their bodies mention, and so on, through functions as well as parameterless bindings — see dependency_graph.

One entry per member of the cycle — every declaration of one strongly-connected component of that graph — each carrying its own declaration’s span (Value::span()) and whether it is a function. Length 1 for a parameterless binding that mentions itself (x = x), length 2 or more for a cycle running through several declarations (a = b beside b = a, or a = f 1 beside f x = a). check_self_dependency orders the members parameterless bindings first, then functions, each group by name, so the first entry is always a parameterless binding and the order is not an artifact of traversal. labels() gives that first entry the primary label and every other entry a secondary one.

A cycle of functions only is never reported: a function’s value exists before its body runs, so f n = f n and mutual recursion between two functions are untouched by this check.

§

Many(Vec<Error>)

Trait Implementations§

Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Vec<EnvError>> for Error

Source§

fn from(errors: Vec<EnvError>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Error>> for Error

Source§

fn from(errors: Vec<Error>) -> Self

Converts to this type from the input type.
Source§

impl PhaseError for Error

Canonicalization errors name source constructs — a value, a type, an operator — so their messages can be written in the same words the user wrote.

The variants whose construction site had a declaration in hand also point at it; see the enum’s own documentation for why the others do not.

Source§

fn message(&self) -> String

One line naming what went wrong, in the vocabulary of the user’s source. Read more
Source§

fn labels(&self) -> Vec<SpanLabel>

The regions of the user’s source this error is about, if it knows any. Read more
Source§

fn notes(&self) -> Vec<String>

Supporting detail, one string per rendered note. Empty by default.
Source§

fn message_and_notes(&self) -> Vec<String>

This error’s message followed by its notes. Read more

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

§

impl UnwindSafe for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.