Skip to content

Commit

Permalink
feat: new error for when multi-validators have the same arg count
Browse files Browse the repository at this point in the history
  • Loading branch information
rvcas committed Mar 17, 2023
1 parent 1571218 commit b43ab73
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/aiken-lang/src/tipo/error.rs
Expand Up @@ -437,6 +437,17 @@ If you really meant to return that last expression, try to replace it with the f
name: String,
},

#[error("I found a multi-validator where both take the same number of arguments.\n")]
#[diagnostic(code("illegal::multi_validator"))]
#[diagnostic(help("Multi-validators cannot take the same number of arguments. One must take 3 arguments\nand the other must take 2 arguments. Both of these take {} arguments.", count.to_string().purple()))]
MultiValidatorEqualArgs {
#[label("{} here", count)]
location: Span,
#[label("and {} here", count)]
other_location: Span,
count: usize,
},

#[error(
"I stumbled upon an invalid (non-local) clause guard '{}'.\n",
name.if_supports_color(Stdout, |s| s.purple())
Expand Down
8 changes: 8 additions & 0 deletions crates/aiken-lang/src/tipo/infer.rs
Expand Up @@ -323,6 +323,14 @@ fn infer_definition(
});
}

if typed_fun.arguments.len() == other_typed_fun.arguments.len() {
return Err(Error::MultiValidatorEqualArgs {
location: typed_fun.location,
other_location: other_typed_fun.location,
count: other_typed_fun.arguments.len(),
});
}

Ok(other_typed_fun)
})
.transpose();
Expand Down

0 comments on commit b43ab73

Please sign in to comment.