fail if log call contains an int expression
This commit is contained in:
parent
2a9e619250
commit
6ab602e88c
3 changed files with 27 additions and 10 deletions
|
@ -0,0 +1,4 @@
|
|||
def main() {
|
||||
log("{}", 1); // 1 is of internal type {integer}
|
||||
return;
|
||||
}
|
4
zokrates_cli/examples/compile_errors/log_wrong_count.zok
Normal file
4
zokrates_cli/examples/compile_errors/log_wrong_count.zok
Normal file
|
@ -0,0 +1,4 @@
|
|||
def main() {
|
||||
log("{} {}", 1f);
|
||||
return;
|
||||
}
|
|
@ -1804,18 +1804,27 @@ impl<'ast, T: Field> Checker<'ast, T> {
|
|||
.collect::<Result<Vec<_>, _>>()
|
||||
.map_err(|e| vec![e])?;
|
||||
|
||||
if expressions.len() != l.len() {
|
||||
return Err(vec![ErrorInner {
|
||||
// we cannot align integer literals here so we ban them
|
||||
match expressions.iter().any(|e| matches!(e, TypedExpression::Int(..))) {
|
||||
true => Err(vec![ErrorInner {
|
||||
pos: Some(pos),
|
||||
message: format!(
|
||||
"Wrong argument count in log call: expected {}, got {}",
|
||||
l.len(),
|
||||
expressions.len()
|
||||
),
|
||||
}]);
|
||||
}
|
||||
message: "Found {integer} literal in log statement, try annotating with a literal suffix".into(),
|
||||
}]),
|
||||
false => {
|
||||
if expressions.len() != l.len() {
|
||||
return Err(vec![ErrorInner {
|
||||
pos: Some(pos),
|
||||
message: format!(
|
||||
"Wrong argument count in log call: expected {}, got {}",
|
||||
l.len(),
|
||||
expressions.len()
|
||||
),
|
||||
}]);
|
||||
}
|
||||
|
||||
Ok(TypedStatement::Log(l, expressions))
|
||||
Ok(TypedStatement::Log(l, expressions))
|
||||
}
|
||||
}
|
||||
}
|
||||
Statement::Return(e) => {
|
||||
let mut errors = vec![];
|
||||
|
|
Loading…
Reference in a new issue