Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic when throwing arity mismatch #477

Merged
merged 4 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions src/constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use std::{fmt::Debug, iter::once, mem::swap};
pub enum ImpossibleConstraint {
ArityMismatch {
atom: Atom<Symbol>,
// The expected arity for this atom
expected: usize,
actual: usize,
},
FunctionMismatch {
expected_output: ArcSort,
Expand Down Expand Up @@ -65,14 +65,10 @@ impl ConstraintError<AtomTerm, ArcSort> {
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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -735,7 +730,6 @@ impl TypeConstraint for SimpleTypeConstraint {
args: arguments.to_vec(),
},
expected: self.sorts.len(),
actual: arguments.len(),
},
)]
} else {
Expand Down Expand Up @@ -815,7 +809,6 @@ impl TypeConstraint for AllEqualTypeConstraint {
args: arguments.to_vec(),
},
expected: exact_length,
actual: arguments.len(),
},
)]
}
Expand Down
4 changes: 1 addition & 3 deletions src/sort/fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@ impl TypeConstraint for FunctionCTorTypeConstraint {
head: self.name,
args: arguments.to_vec(),
},
expected: 1,
actual: 0,
expected: 2,
},
)];
}
Expand All @@ -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,
},
)];
}
Expand Down
1 change: 1 addition & 0 deletions tests/fail-typecheck/arity-mismatch.egg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(+ 1 2 3)
1 change: 1 addition & 0 deletions tests/fail-typecheck/set-a-primitive.egg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(set (+ 1 2) 3)
Loading