Skip to main content

geam_core/planner/error/
invalid.rs

1use crate::plan::ValueType;
2use ecow::EcoString;
3use thiserror::Error;
4
5#[derive(Debug, Error, Clone, PartialEq, Eq)]
6pub enum InvalidTypedAstReason {
7    #[error("custom type {package}:{module}.{name}: {reason}")]
8    CustomType {
9        package: EcoString,
10        module: EcoString,
11        name: EcoString,
12        reason: Box<InvalidCustomTypeReason>,
13    },
14    #[error("function shape {name}: {reason}")]
15    FunctionShape {
16        name: EcoString,
17        reason: InvalidFunctionShapeReason,
18    },
19    #[error("generated assignment")]
20    GeneratedAssignment,
21    #[error("use statement")]
22    UseStatement,
23    #[error("invalid expression node")]
24    InvalidExpressionNode,
25    #[error("expression shape refinement: expected {expected:?}, got {actual:?}")]
26    ExpressionShapeRefinement {
27        expected: ValueType,
28        actual: ValueType,
29    },
30    #[error("pattern shape: {reason}")]
31    PatternShape { reason: InvalidPatternShapeReason },
32    #[error("expression shape: {kind}")]
33    ExpressionShape { kind: InvalidExpressionShapeKind },
34    #[error("expression type: expected {expected}, got {actual}")]
35    ExpressionType {
36        expected: InvalidExpressionType,
37        actual: InvalidExpressionType,
38    },
39    #[error("expression value type: expected {expected:?}, got {actual:?}")]
40    ExpressionValueTypeMismatch {
41        expected: ValueType,
42        actual: ValueType,
43    },
44    #[error("expression type has no supported runtime family; expected {expected}")]
45    UnsupportedExpressionType { expected: InvalidExpressionType },
46    #[error("call shape: {reason}")]
47    CallShape { reason: InvalidCallShapeReason },
48    #[error("case shape: {reason}")]
49    CaseShape { reason: InvalidCaseShapeReason },
50    #[error("pipeline shape: {reason}")]
51    PipelineShape { reason: InvalidPipelineShapeReason },
52    #[error("record update shape: {reason}")]
53    RecordUpdateShape {
54        reason: InvalidRecordUpdateShapeReason,
55    },
56    #[error("module reference {module}.{name}: {reason}")]
57    ModuleReference {
58        module: EcoString,
59        name: EcoString,
60        reason: InvalidModuleReferenceReason,
61    },
62    #[error("use shape: {reason}")]
63    UseShape { reason: InvalidUseShapeReason },
64    #[error("unknown local variable: {name}")]
65    UnknownLocal { name: EcoString },
66}
67
68#[derive(Debug, Error, Clone, PartialEq, Eq)]
69pub enum InvalidPatternShapeReason {
70    #[error("pattern type: expected {expected:?}, got {actual:?}")]
71    TypeMismatch {
72        expected: ValueType,
73        actual: ValueType,
74    },
75    #[error("pattern annotation has no supported runtime type")]
76    UnsupportedType,
77    #[error("{actual} pattern cannot represent {expected:?}")]
78    KindMismatch {
79        expected: ValueType,
80        actual: PatternKind,
81    },
82    #[error("tuple pattern arity: expected {expected}, got {actual}")]
83    TupleArity { expected: usize, actual: usize },
84    #[error("list tail must bind or discard, got {actual}")]
85    ListTailKind { actual: PatternKind },
86    #[error("{actual} pattern cannot be used as a total binding")]
87    BindingKind { actual: PatternKind },
88    #[error("binding aliases cannot contain another alias")]
89    NestedBindingAlias,
90    #[error("{actual} binding cannot represent {expected:?}")]
91    BindingShape {
92        expected: ValueType,
93        actual: PatternKind,
94    },
95    #[error("binding shapes for {type_:?} are incompatible")]
96    BindingShapeConflict { type_: ValueType },
97    #[error("binding constructor {expected} does not match {actual:?}")]
98    BindingConstructorRefinement {
99        expected: usize,
100        actual: Option<usize>,
101    },
102    #[error("list binding must not contain elements, got {actual}")]
103    ListBindingElements { actual: usize },
104    #[error("list binding must contain a tail")]
105    ListBindingTailMissing,
106    #[error("constructor binding is refutable across {constructors} constructors")]
107    RefutableBindingConstructor { constructors: usize },
108    #[error("bit-array binding segment count: expected 1, got {actual}")]
109    BitArrayBindingSegmentCount { actual: usize },
110    #[error("bit-array binding segment must not have a size")]
111    BitArrayBindingSegmentSize,
112    #[error("bit-array binding segment must use the bits option")]
113    BitArrayBindingSegmentOptions,
114    #[error("unsized bit-array segment {index} is not the final segment of {count}")]
115    BitArrayUnsizedSegment { index: usize, count: usize },
116    #[error("bit-array segment options: {reason}")]
117    BitArraySegmentOptions {
118        reason: InvalidBitArraySegmentOptionsReason,
119    },
120    #[error("bit-array size must use a size node, got {actual}")]
121    BitArraySizePattern { actual: PatternKind },
122    #[error("bit-array size variable {name} has no constructor metadata")]
123    BitArraySizeUnresolved { name: EcoString },
124    #[error("bit-array size variable {name} has an unsupported source")]
125    BitArraySizeSource { name: EcoString },
126    #[error("bit-array size constant is not an integer expression")]
127    BitArraySizeConstant,
128    #[error("{actual:?} cannot be used as a refutable assertion subject")]
129    AssertSubject { actual: ValueType },
130    #[error("invalid pattern node")]
131    InvalidNode,
132    #[error("bit-array size node used as a pattern")]
133    BitArraySizeNode,
134    #[error("constructor metadata is unresolved")]
135    UnresolvedConstructor,
136    #[error("constructor module: expected {expected}, got {actual}")]
137    ConstructorModule {
138        expected: EcoString,
139        actual: EcoString,
140    },
141    #[error("constructor name: expected {expected}, got {actual}")]
142    ConstructorName {
143        expected: EcoString,
144        actual: EcoString,
145    },
146    #[error("constructor index: expected {expected}, got {actual}")]
147    ConstructorIndex { expected: usize, actual: usize },
148    #[error("constructor arity: expected {expected}, got {actual}")]
149    ConstructorArity { expected: usize, actual: usize },
150    #[error("constructor pattern cannot represent {type_:?}")]
151    ConstructorType { type_: ValueType },
152    #[error("constructor spread is invalid for {type_:?}")]
153    ConstructorSpread { type_: ValueType },
154}
155
156#[derive(Debug, Error, Clone, Copy, PartialEq, Eq)]
157pub enum InvalidBitArraySegmentOptionsReason {
158    #[error("multiple segment kinds")]
159    MultipleKinds,
160    #[error("multiple signedness options")]
161    MultipleSignedness,
162    #[error("multiple endianness options")]
163    MultipleEndianness,
164    #[error("multiple size options")]
165    MultipleSizes,
166    #[error("multiple unit options")]
167    MultipleUnits,
168    #[error("unit option without a size")]
169    UnitWithoutSize,
170    #[error("zero unit")]
171    ZeroUnit,
172    #[error("options incompatible with the segment kind")]
173    Incompatible,
174}
175
176#[derive(Debug, Error, Clone, Copy, PartialEq, Eq)]
177pub enum PatternKind {
178    #[error("integer")]
179    Int,
180    #[error("float")]
181    Float,
182    #[error("string")]
183    String,
184    #[error("variable")]
185    Variable,
186    #[error("bit-array size")]
187    BitArraySize,
188    #[error("alias")]
189    Assign,
190    #[error("discard")]
191    Discard,
192    #[error("list")]
193    List,
194    #[error("constructor")]
195    Constructor,
196    #[error("tuple")]
197    Tuple,
198    #[error("bit array")]
199    BitArray,
200    #[error("string prefix")]
201    StringPrefix,
202    #[error("invalid")]
203    Invalid,
204}
205
206#[derive(Debug, Error, Clone, PartialEq, Eq)]
207pub enum InvalidCustomTypeReason {
208    #[error("type parameter {index} is not a generic parameter")]
209    DefinitionParameter { index: usize },
210    #[error("field {field} of constructor {constructor} has no supported type template")]
211    DefinitionField {
212        constructor: EcoString,
213        field: usize,
214    },
215    #[error("template parameter {index} is outside {available} type arguments")]
216    TemplateParameterIndex { index: usize, available: usize },
217    #[error("template shape expected {expected:?}, got {actual:?}")]
218    TemplateShapeMismatch {
219        expected: ValueType,
220        actual: ValueType,
221    },
222    #[error("parameter {parameter} inferred incompatible shapes {previous:?} and {actual:?}")]
223    ConflictingParameterShape {
224        parameter: usize,
225        previous: ValueType,
226        actual: ValueType,
227    },
228    #[error("custom type definition is missing")]
229    MissingDefinition,
230    #[error("type argument count: expected {expected}, got {actual}")]
231    TypeArgumentCount { expected: usize, actual: usize },
232    #[error("constructor index {index} is outside {available} constructors")]
233    ConstructorIndex { index: usize, available: usize },
234    #[error("constructor {index} name: expected {expected}, got {actual}")]
235    ConstructorName {
236        index: usize,
237        expected: EcoString,
238        actual: EcoString,
239    },
240    #[error("constructor module: expected {expected}, got {actual}")]
241    ConstructorModule {
242        expected: EcoString,
243        actual: EcoString,
244    },
245    #[error("constructor arity: expected {expected}, got {actual}")]
246    ConstructorArity { expected: usize, actual: usize },
247    #[error("constructor result is {actual:?}, not a custom type")]
248    ConstructorType { actual: ValueType },
249    #[error("field index {index} is outside {available} fields")]
250    FieldIndex { index: usize, available: usize },
251    #[error("field {index} label: expected {expected:?}, got {actual:?}")]
252    FieldLabel {
253        index: usize,
254        expected: Option<EcoString>,
255        actual: Option<EcoString>,
256    },
257    #[error("field {index} type: expected {expected:?}, got {actual:?}")]
258    FieldType {
259        index: usize,
260        expected: ValueType,
261        actual: ValueType,
262    },
263    #[error("field {index} has incompatible result shape for {type_:?}")]
264    FieldShapeConflict { index: usize, type_: ValueType },
265}
266
267#[derive(Debug, Error, Clone, PartialEq, Eq)]
268pub enum InvalidFunctionShapeReason {
269    #[error("function argument types do not match signature")]
270    ArgumentTypeMismatch,
271    #[error("anonymous functions are not module functions")]
272    Anonymous,
273    #[error("empty function bodies are not supported")]
274    EmptyBody,
275    #[error("labelled function argument")]
276    LabelledArgument,
277    #[error("function expression has type {actual:?}")]
278    ExpressionType { actual: ValueType },
279    #[error("function return type does not match body")]
280    ReturnTypeMismatch,
281}
282
283#[derive(Debug, Error, Clone, PartialEq, Eq)]
284pub enum InvalidExpressionShapeKind {
285    #[error("bit-array constant size is not an integer")]
286    BitArrayConstantSize,
287    #[error("bit-array float size: got {actual}")]
288    BitArrayFloatSize { actual: usize },
289    #[error("bit-array segment has multiple kinds")]
290    BitArrayMultipleKinds,
291    #[error("bit-array segment cannot infer a kind from {actual:?}")]
292    BitArrayImplicitKind { actual: ValueType },
293    #[error("bit-array string segment has a size or non-default unit")]
294    BitArrayStringOptions,
295    #[error("bit-array codepoint segment has incompatible options")]
296    BitArrayUtfCodepointOptions,
297    #[error("unsupported bit-array segment option")]
298    BitArrayUnsupportedOption,
299    #[error("constant local variable")]
300    ConstantLocalVariable,
301    #[error("constant variable has no constructor metadata")]
302    ConstantMissingConstructor,
303    #[error("invalid constant node")]
304    ConstantNode,
305    #[error("constant record constructor kind")]
306    ConstantRecordConstructorKind,
307    #[error("constant record kind")]
308    ConstantRecordKind,
309    #[error("constant record constructor metadata is missing")]
310    ConstantRecordMissingConstructor,
311    #[error("constant record argument count: expected {expected}, got {actual}")]
312    ConstantRecordArgumentCount { expected: usize, actual: usize },
313    #[error("constant record argument {index} label: expected {expected:?}, got {actual:?}")]
314    ConstantRecordArgumentLabel {
315        index: usize,
316        expected: Option<EcoString>,
317        actual: Option<EcoString>,
318    },
319    #[error("constant record constructor type: got {actual:?}")]
320    ConstantRecordConstructorType { actual: Option<ValueType> },
321    #[error("constant prelude constructor {name}/{arity}: got {actual:?}")]
322    ConstantPreludeConstructor {
323        name: EcoString,
324        arity: usize,
325        actual: Option<ValueType>,
326    },
327    #[error("constant record update")]
328    ConstantRecordUpdate,
329    #[error("constant list element type")]
330    ConstantListElementType,
331    #[error("constant list type: got {actual:?}")]
332    ConstantListType { actual: Option<ValueType> },
333    #[error("constant tuple elements: expected {expected:?}, got {actual:?}")]
334    ConstantTupleElements {
335        expected: Vec<ValueType>,
336        actual: Vec<ValueType>,
337    },
338    #[error("constant tuple type: got {actual:?}")]
339    ConstantTupleType { actual: Option<ValueType> },
340    #[error("echo expression is missing")]
341    EchoExpressionMissing,
342    #[error("function capture literal")]
343    FunctionCaptureLiteral,
344    #[error("function literal kind")]
345    FunctionLiteralKind,
346    #[error("generated todo message")]
347    GeneratedTodoMessage,
348    #[error("invalid guard node")]
349    GuardNode,
350    #[error("guard local shape")]
351    GuardLocalShape,
352    #[error("guard function local shape")]
353    GuardFunctionLocalShape,
354    #[error("list spread has no prefix elements")]
355    ListSpreadEmptyPrefix,
356    #[error("list expression type: got {actual:?}")]
357    ListType { actual: ValueType },
358    #[error("list index expression shape for {type_:?}")]
359    ListIndexShape { type_: ValueType },
360    #[error("local binding shape")]
361    LocalBindingShape,
362    #[error("invalid module constant node")]
363    ModuleConstantNode,
364    #[error("module constant bit-array float size: got {actual}")]
365    ModuleConstantBitArrayFloatSize { actual: usize },
366    #[error("module constant bit-array segment cannot infer a kind from {actual:?}")]
367    ModuleConstantBitArrayImplicitKind { actual: ValueType },
368    #[error("module constant bit-array segment has multiple kinds")]
369    ModuleConstantBitArrayMultipleKinds,
370    #[error("module constant bit-array size is not an integer")]
371    ModuleConstantBitArraySize,
372    #[error("module constant bit-array string segment has a size or non-default unit")]
373    ModuleConstantBitArrayStringOptions,
374    #[error("module constant bit-array codepoint option")]
375    ModuleConstantBitArrayCodepointOption,
376    #[error("unsupported module constant bit-array segment option")]
377    ModuleConstantBitArrayUnsupportedOption,
378    #[error("module constant list spread has no prefix elements")]
379    ModuleConstantListSpreadEmptyPrefix,
380    #[error("module constant list type: got {actual:?}")]
381    ModuleConstantListType { actual: ValueType },
382    #[error("module constant local variable")]
383    ModuleConstantLocalVariable,
384    #[error("module constant variable has no constructor metadata")]
385    ModuleConstantMissingConstructor,
386    #[error("module constant record kind")]
387    ModuleConstantRecordKind,
388    #[error("module constant record constructor metadata is missing")]
389    ModuleConstantRecordMissingConstructor,
390    #[error("module constant record argument count: expected {expected}, got {actual}")]
391    ModuleConstantRecordArgumentCount { expected: usize, actual: usize },
392    #[error("module constant record argument {index} label: expected {expected:?}, got {actual:?}")]
393    ModuleConstantRecordArgumentLabel {
394        index: usize,
395        expected: Option<EcoString>,
396        actual: Option<EcoString>,
397    },
398    #[error("module constant record value must be custom, got {actual:?}")]
399    ModuleConstantRecordCustomShape { actual: ValueType },
400    #[error("module constant record reference must be a function, got {actual:?}")]
401    ModuleConstantRecordFunctionShape { actual: ValueType },
402    #[error("module constant prelude constructor {name}/{arity}: got {actual:?}")]
403    ModuleConstantPreludeConstructor {
404        name: EcoString,
405        arity: usize,
406        actual: ValueType,
407    },
408    #[error("module constant record update")]
409    ModuleConstantRecordUpdate,
410    #[error("module constant storage shape")]
411    ModuleConstantStorageShape,
412    #[error("module constant tuple arity: expected {expected}, got {actual}")]
413    ModuleConstantTupleArity { expected: usize, actual: usize },
414    #[error("module constant tuple type: got {actual:?}")]
415    ModuleConstantTupleType { actual: ValueType },
416    #[error("positional access")]
417    PositionalAccess,
418    #[error("custom constructor metadata is not a record")]
419    CustomConstructorKind,
420    #[error("record access")]
421    RecordAccess,
422    #[error("tuple expression arity: expected {expected}, got {actual}")]
423    TupleArity { expected: usize, actual: usize },
424    #[error("tuple index {index} is outside {available} elements")]
425    TupleIndex { index: usize, available: usize },
426    #[error("tuple expression type: got {actual:?}")]
427    TupleType { actual: ValueType },
428    #[error("variable function local shape")]
429    VariableFunctionLocalShape,
430    #[error("variable prelude constructor {name}/{arity}: got {actual:?}")]
431    VariablePreludeConstructor {
432        name: EcoString,
433        arity: usize,
434        actual: ValueType,
435    },
436}
437
438#[derive(Debug, Error, Clone, PartialEq, Eq)]
439pub enum InvalidRecordUpdateShapeReason {
440    #[error("record constructor argument count: expected {expected}, got {actual}")]
441    ArgumentCount { expected: usize, actual: usize },
442    #[error("record constructor argument {index} label: expected {expected:?}, got {actual:?}")]
443    ArgumentLabel {
444        index: usize,
445        expected: Option<EcoString>,
446        actual: Option<EcoString>,
447    },
448    #[error(
449        "record update base assignment: requires assignment {requires_assignment}, got {has_assignment}"
450    )]
451    BaseAssignment {
452        requires_assignment: bool,
453        has_assignment: bool,
454    },
455    #[error("record constructor expression")]
456    ConstructorExpression,
457    #[error("record constructor kind")]
458    ConstructorKind,
459    #[error("record constructor name: expected {expected}, got {actual}")]
460    ConstructorName {
461        expected: EcoString,
462        actual: EcoString,
463    },
464    #[error("record constructor result type: expected {expected:?}, got {actual:?}")]
465    ConstructorResultType {
466        expected: ValueType,
467        actual: ValueType,
468    },
469    #[error("record update implicit argument {index} origin: got {actual}")]
470    ImplicitArgumentOrigin {
471        index: usize,
472        actual: RecordUpdateArgumentOrigin,
473    },
474    #[error("record update implicit argument {argument} is not a field access")]
475    ImplicitFieldExpression { argument: usize },
476    #[error(
477        "record update implicit argument {argument} field index: expected {expected}, got {actual}"
478    )]
479    ImplicitFieldIndex {
480        argument: usize,
481        expected: usize,
482        actual: u64,
483    },
484    #[error(
485        "record update implicit argument {argument} field label: expected {expected:?}, got {actual:?}"
486    )]
487    ImplicitFieldLabel {
488        argument: usize,
489        expected: Option<EcoString>,
490        actual: Option<EcoString>,
491    },
492    #[error(
493        "record update implicit argument {argument} field type: expected {expected:?}, got {actual:?}"
494    )]
495    ImplicitFieldType {
496        argument: usize,
497        expected: ValueType,
498        actual: ValueType,
499    },
500    #[error("record update implicit argument {argument} generated target kind")]
501    ImplicitGeneratedTargetKind { argument: usize },
502    #[error("record update implicit argument {argument} generated target origin")]
503    ImplicitGeneratedTargetOrigin { argument: usize },
504    #[error(
505        "record update implicit argument {argument} generated target type: expected {expected:?}, got {actual:?}"
506    )]
507    ImplicitGeneratedTargetType {
508        argument: usize,
509        expected: ValueType,
510        actual: ValueType,
511    },
512    #[error("record update implicit argument {argument} original target constructor")]
513    ImplicitOriginalTargetConstructor { argument: usize },
514    #[error("record update implicit argument {argument} target is not a variable")]
515    ImplicitTargetExpression { argument: usize },
516    #[error(
517        "record update implicit argument {argument} target name: expected {expected}, got {actual}"
518    )]
519    ImplicitTargetName {
520        argument: usize,
521        expected: EcoString,
522        actual: EcoString,
523    },
524    #[error("record update source is not a custom type: got {actual:?}")]
525    UpdatedSourceFamily { actual: ValueType },
526    #[error("record update source type: expected {expected:?}, got {actual:?}")]
527    UpdatedSourceType {
528        expected: ValueType,
529        actual: ValueType,
530    },
531}
532
533#[derive(Debug, Error, Clone, Copy, PartialEq, Eq)]
534pub enum RecordUpdateArgumentOrigin {
535    #[error("incorrect-arity use")]
536    IncorrectArityUse,
537    #[error("pattern field spread")]
538    PatternFieldSpread,
539    #[error("pipe")]
540    Pipe,
541    #[error("record update")]
542    RecordUpdate,
543    #[error("use")]
544    Use,
545}
546
547#[derive(Debug, Error, Clone, Copy, PartialEq, Eq)]
548pub enum InvalidExpressionType {
549    #[error("type parameter")]
550    TypeParameter,
551    #[error("Int")]
552    Int,
553    #[error("String")]
554    String,
555    #[error("BitArray")]
556    BitArray,
557    #[error("UtfCodepoint")]
558    UtfCodepoint,
559    #[error("custom type")]
560    Custom,
561    #[error("external type")]
562    External,
563    #[error("Float")]
564    Float,
565    #[error("Bool")]
566    Bool,
567    #[error("Nil")]
568    Nil,
569    #[error("Tuple")]
570    Tuple,
571    #[error("List")]
572    List,
573    #[error("Function")]
574    Function,
575}
576
577impl InvalidExpressionType {
578    pub(crate) fn from_value_type(type_: ValueType) -> Self {
579        match type_ {
580            ValueType::Parameter(_) => Self::TypeParameter,
581            ValueType::Int => Self::Int,
582            ValueType::String => Self::String,
583            ValueType::BitArray => Self::BitArray,
584            ValueType::UtfCodepoint => Self::UtfCodepoint,
585            ValueType::Custom(_) => Self::Custom,
586            ValueType::External(_) => Self::External,
587            ValueType::Float => Self::Float,
588            ValueType::Bool => Self::Bool,
589            ValueType::Nil => Self::Nil,
590            ValueType::Tuple(_) => Self::Tuple,
591            ValueType::List(_) => Self::List,
592            ValueType::Function(_) => Self::Function,
593        }
594    }
595}
596
597#[cfg(test)]
598mod tests {
599    use super::InvalidExpressionType;
600    use crate::plan::{ExternalType, ExternalTypeName, ValueType};
601
602    #[test]
603    fn classifies_external_value_types() {
604        let type_ = ExternalType::new(
605            ExternalTypeName::new("application".into(), "main".into(), "Token".into()),
606            Vec::new(),
607        );
608
609        assert_eq!(
610            InvalidExpressionType::from_value_type(ValueType::External(type_)),
611            InvalidExpressionType::External,
612        );
613    }
614}
615
616#[derive(Debug, Error, Clone, PartialEq, Eq)]
617pub enum InvalidCallShapeReason {
618    #[error("call argument count: expected {expected}, got {actual}")]
619    ArgumentCount { expected: usize, actual: usize },
620    #[error("call argument {index} label: expected {expected:?}, got {actual}")]
621    ArgumentLabel {
622        index: usize,
623        expected: Option<EcoString>,
624        actual: EcoString,
625    },
626    #[error("call argument {index} shape is incompatible with {type_:?}")]
627    ArgumentShape { index: usize, type_: ValueType },
628    #[error("call argument {index} type: expected {expected:?}, got {actual:?}")]
629    ArgumentType {
630        index: usize,
631        expected: ValueType,
632        actual: ValueType,
633    },
634    #[error("function instantiation argument count: expected {expected}, got {actual}")]
635    FunctionInstantiationArgumentCount { expected: usize, actual: usize },
636    #[error("function instantiation argument {index}: expected {expected:?}, got {actual:?}")]
637    FunctionInstantiationArgumentShape {
638        index: usize,
639        expected: ValueType,
640        actual: ValueType,
641    },
642    #[error("function instantiation return shape: expected {expected:?}, got {actual:?}")]
643    FunctionInstantiationReturnShape {
644        expected: ValueType,
645        actual: ValueType,
646    },
647    #[error("function instantiation has an unresolved type parameter")]
648    FunctionInstantiationUnresolvedParameter,
649    #[error("function value return type: expected {expected:?}, got {actual:?}")]
650    FunctionValueReturnType {
651        expected: ValueType,
652        actual: ValueType,
653    },
654    #[error("implicit call argument at index {index}")]
655    ImplicitArgument { index: usize },
656    #[error("record constructor argument count: expected {expected}, got {actual}")]
657    RecordConstructorArgumentCount { expected: usize, actual: usize },
658}
659
660#[derive(Debug, Error, Clone, PartialEq, Eq)]
661pub enum InvalidModuleReferenceReason {
662    #[error("module is not linked")]
663    UnlinkedModule,
664    #[error("function is missing from the linked registry")]
665    MissingFunction,
666    #[error("constant is missing from the linked registry")]
667    MissingConstant,
668    #[error("constant is not callable")]
669    NonCallableConstant,
670    #[error("function constructor module is {actual}")]
671    FunctionModule { actual: EcoString },
672    #[error("function constructor name is {actual}")]
673    FunctionName { actual: EcoString },
674    #[error("external function")]
675    ExternalFunction,
676    #[error("record constructor name is {actual}")]
677    RecordConstructorName { actual: EcoString },
678    #[error("record constructor result shape")]
679    RecordConstructorResultShape,
680    #[error("function value type")]
681    FunctionType,
682    #[error("function signature instantiation")]
683    FunctionInstantiation,
684    #[error("function reference result shape")]
685    FunctionReferenceShape,
686    #[error("constant signature instantiation")]
687    ConstantInstantiation,
688}
689
690#[derive(Debug, Error, Clone, PartialEq, Eq)]
691pub enum InvalidCaseShapeReason {
692    #[error("branch annotation type: expected {expected:?}, got {actual:?}")]
693    BranchAnnotatedTypeMismatch {
694        expected: ValueType,
695        actual: ValueType,
696    },
697    #[error("branch shapes are incompatible: expected {expected:?}, got {actual:?}")]
698    BranchShapeIncompatibility {
699        expected: ValueType,
700        actual: ValueType,
701    },
702    #[error("branch family assembly: expected {expected:?}, got {actual:?}")]
703    BranchFamilyAssemblyMismatch {
704        expected: ValueType,
705        actual: ValueType,
706    },
707    #[error("empty clauses")]
708    EmptyClauses,
709    #[error("empty subjects")]
710    EmptySubjects,
711    #[error("compiled case clause index is out of bounds")]
712    CompiledCaseClauseIndex,
713    #[error("compiled case contains a reachable failure")]
714    CompiledCaseFailure,
715    #[error("compiled case guard index is out of bounds")]
716    CompiledCaseGuardIndex,
717    #[error("compiled case guard does not match its clause")]
718    CompiledCaseGuard,
719    #[error("compiled case subject count does not match case subjects")]
720    CompiledCaseSubjectCountMismatch,
721    #[error("missing false pattern")]
722    MissingFalsePattern,
723    #[error("missing fallback pattern")]
724    MissingFallbackPattern,
725    #[error("missing true pattern")]
726    MissingTruePattern,
727    #[error("case pattern count: expected {expected}, got {actual}")]
728    PatternSubjectCountMismatch { expected: usize, actual: usize },
729}
730
731#[derive(Debug, Error, Clone, Copy, PartialEq, Eq)]
732pub enum InvalidPipelineShapeReason {
733    #[error("invalid echo step")]
734    EchoStep,
735    #[error("hole capture argument is not a variable binding")]
736    HoleCaptureBinding,
737    #[error("hole capture argument count: expected 1, got {actual}")]
738    HoleCaptureArgumentCount { actual: usize },
739    #[error("hole capture is not a function literal")]
740    HoleCaptureFunction,
741    #[error("hole capture function has the wrong literal kind")]
742    HoleCaptureLiteralKind,
743    #[error("hole capture use count: expected 1, got {actual}")]
744    HoleCaptureUseCount { actual: usize },
745    #[error("hole body has an implicit argument at index {index}")]
746    HoleBodyImplicitArgument { index: usize },
747    #[error("hole body is not a call")]
748    HoleBodyNotCall,
749    #[error("hole body statement count: expected 1, got {actual}")]
750    HoleBodyStatementCount { actual: usize },
751    #[error("hole wrapper argument count: expected 1, got {actual}")]
752    HoleWrapperArgumentCount { actual: usize },
753    #[error("missing pipe argument")]
754    MissingPipeArgument,
755    #[error("multiple pipe arguments at indices {first} and {second}")]
756    MultiplePipeArguments { first: usize, second: usize },
757    #[error("non-call pipeline step")]
758    NonCallStep,
759    #[error("unsupported pipe argument at index {index}")]
760    UnsupportedPipeArgument { index: usize },
761}
762
763#[derive(Debug, Error, Clone, Copy, PartialEq, Eq)]
764pub enum InvalidUseShapeReason {
765    #[error("callback literal kind is not use")]
766    CallbackLiteralKindNotUse { index: usize },
767    #[error("callback is not the last argument")]
768    CallbackNotLast { index: usize, arguments: usize },
769    #[error("callback argument is not a function literal")]
770    CallbackNotFunctionLiteral { index: usize },
771    #[error("invalid generated assignment")]
772    InvalidGeneratedAssignment { index: usize },
773    #[error("missing callback")]
774    MissingCallback,
775    #[error("multiple callbacks at indices {first} and {second}")]
776    MultipleCallbacks { first: usize, second: usize },
777    #[error("non-call use right hand side")]
778    NonCallRhs,
779    #[error("unexpected variable use assignment at index {index}")]
780    UnexpectedVariableAssignment { index: usize },
781    #[error("unsupported implicit use argument at index {index}")]
782    UnsupportedImplicitArgument { index: usize },
783}