diff --git a/src/constraint.rs b/src/constraint.rs index 35f61f9e4..0fd053888 100644 --- a/src/constraint.rs +++ b/src/constraint.rs @@ -21,8 +21,8 @@ use std::{fmt::Debug, iter::once, mem::swap}; pub enum ImpossibleConstraint { ArityMismatch { atom: Atom, + // The expected arity for this atom expected: usize, - actual: usize, }, FunctionMismatch { expected_output: ArcSort, @@ -65,14 +65,10 @@ impl ConstraintError { ConstraintError::ImpossibleCaseIdentified(ImpossibleConstraint::ArityMismatch { atom, expected, - actual, - }) => { - assert_eq!(*actual, atom.args.len() - 1); - TypeError::Arity { - expr: atom.to_expr(), - expected: *expected, - } - } + }) => TypeError::Arity { + expr: atom.to_expr(), + expected: *expected - 1, + }, ConstraintError::ImpossibleCaseIdentified(ImpossibleConstraint::FunctionMismatch { expected_output, expected_input, @@ -635,8 +631,7 @@ fn get_atom_application_constraints( head: *head, args: args.to_vec(), }, - expected: typ.input.len(), - actual: args.len() - 1, + expected: typ.input.len() + 1, }, )); } else { @@ -735,7 +730,6 @@ impl TypeConstraint for SimpleTypeConstraint { args: arguments.to_vec(), }, expected: self.sorts.len(), - actual: arguments.len(), }, )] } else { @@ -815,7 +809,6 @@ impl TypeConstraint for AllEqualTypeConstraint { args: arguments.to_vec(), }, expected: exact_length, - actual: arguments.len(), }, )] } diff --git a/src/sort/fn.rs b/src/sort/fn.rs index 83e683f1b..652a11b77 100644 --- a/src/sort/fn.rs +++ b/src/sort/fn.rs @@ -258,8 +258,7 @@ impl TypeConstraint for FunctionCTorTypeConstraint { head: self.name, args: arguments.to_vec(), }, - expected: 1, - actual: 0, + expected: 2, }, )]; } @@ -284,7 +283,6 @@ impl TypeConstraint for FunctionCTorTypeConstraint { args: arguments.to_vec(), }, expected: self.function.inputs.len() + func_type.input.len() + 1, - actual: arguments.len() - 1, }, )]; } diff --git a/tests/fail-typecheck/arity-mismatch.egg b/tests/fail-typecheck/arity-mismatch.egg new file mode 100644 index 000000000..1a9372c5c --- /dev/null +++ b/tests/fail-typecheck/arity-mismatch.egg @@ -0,0 +1 @@ +(+ 1 2 3) diff --git a/tests/fail-typecheck/set-a-primitive.egg b/tests/fail-typecheck/set-a-primitive.egg new file mode 100644 index 000000000..cd564f549 --- /dev/null +++ b/tests/fail-typecheck/set-a-primitive.egg @@ -0,0 +1 @@ +(set (+ 1 2) 3)