Skip to content

Commit

Permalink
Remove argument count restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
imaqtkatt committed Mar 8, 2024
1 parent e9fbc96 commit cdf8bba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
12 changes: 6 additions & 6 deletions src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::term::{
},
display::DisplayFn,
transform::{
apply_args::ArgError, encode_pattern_matching::MatchErr, resolve_refs::ReferencedMainErr,
apply_args::PatternArgError, encode_pattern_matching::MatchErr, resolve_refs::ReferencedMainErr,
simplify_ref_to_ref::CyclicDefErr,
},
Name,
Expand Down Expand Up @@ -119,7 +119,7 @@ pub enum Error {
EntryPoint(EntryErr),
TopLevel(TopLevelErr),
Custom(String),
ArgError(ArgError),
PatternArgError(PatternArgError),
RepeatedBind(RepeatedBindWarn),
}

Expand All @@ -140,7 +140,7 @@ impl Error {
Error::EntryPoint(err) => write!(f, "{err}"),
Error::TopLevel(err) => write!(f, "{err}"),
Error::Custom(err) => write!(f, "{err}"),
Error::ArgError(err) => write!(f, "{err}"),
Error::PatternArgError(err) => write!(f, "{err}"),
Error::RepeatedBind(err) => write!(f, "{err}"),
})
}
Expand Down Expand Up @@ -188,9 +188,9 @@ impl From<TopLevelErr> for Error {
}
}

impl From<ArgError> for Error {
fn from(value: ArgError) -> Self {
Self::ArgError(value)
impl From<PatternArgError> for Error {
fn from(value: PatternArgError) -> Self {
Self::PatternArgError(value)
}
}

Expand Down
24 changes: 7 additions & 17 deletions src/term/transform/apply_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@ use crate::{
};

#[derive(Clone, Debug)]
pub enum ArgError {
PatternArgError,
ArityArgError { expected: usize, got: usize },
}
pub struct PatternArgError(Pattern);

impl Display for ArgError {
impl Display for PatternArgError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ArgError::PatternArgError => write!(f, ""),
ArgError::ArityArgError { expected, got } => write!(f, "Expected {expected} arguments, got {got}."),
}
write!(f, "Expected a variable pattern, found '{}'.", self.0)
}
}

Expand All @@ -37,17 +31,13 @@ impl Ctx<'_> {
if let Some(entrypoint) = &self.book.entrypoint {
let main_def = &mut self.book.defs[entrypoint];

if !main_def.rules[0].pats.iter().all(|pat| matches!(pat, Pattern::Var(Some(..)))) {
self.info.def_error(entrypoint.clone(), ArgError::PatternArgError);
for pat in &main_def.rules[0].pats {
if !matches!(pat, Pattern::Var(Some(..))) {
self.info.def_error(entrypoint.clone(), PatternArgError(pat.clone()));
}
}

if let Some(args) = args {
let expected = main_def.rules[0].pats.len();
let got = args.len();
if expected != got {
self.info.error(ArgError::ArityArgError { expected, got });
}

main_def.convert_match_def_to_term();
let main_body = &mut self.book.defs[entrypoint].rule_mut().body;

Expand Down

0 comments on commit cdf8bba

Please sign in to comment.