Implement fix

This commit is contained in:
d0cd 2022-10-27 20:21:18 -07:00
parent adb382cb33
commit 9907d89886
3 changed files with 16 additions and 0 deletions

View File

@ -322,6 +322,8 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> {
// If `input.start` is a literal, instantiate it as a value.
if let Expression::Literal(literal) = &input.start {
input.start_value.replace(Some(Value::from(literal)));
} else {
self.emit_err(TypeCheckerError::loop_bound_must_be_a_literal(input.start.span()));
}
self.visit_expression(&input.stop, iter_type);
@ -329,6 +331,8 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> {
// If `input.stop` is a literal, instantiate it as a value.
if let Expression::Literal(literal) = &input.stop {
input.stop_value.replace(Some(Value::from(literal)));
} else {
self.emit_err(TypeCheckerError::loop_bound_must_be_a_literal(input.stop.span()));
}
}

View File

@ -423,4 +423,11 @@ create_messages!(
msg: format!("Cannot call a local transition function from a transition function."),
help: None,
}
@formatted
loop_bound_must_be_a_literal {
args: (),
msg: format!("Loop bound must be a literal."),
help: None,
}
);

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [ETYC0372049]: Loop bound must be a literal.\n --> compiler-test:12:28\n |\n 12 | for i:u64 in 0u64..amount {\n | ^^^^^^\n"