Skip to content

Commit

Permalink
Attempt to fix missing type inference for loop vars.
Browse files Browse the repository at this point in the history
Doesn't work because it loses track of `while foo/any := ...:`

See #1815
  • Loading branch information
floitsch committed Sep 18, 2023
1 parent 52f7f66 commit 61c0392
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/compiler/type_check.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,21 @@ class TypeChecker : public ReturningVisitor<Type> {
}

Type visit_While(While* node) {
auto condition_type = visit(node->condition());
auto condition = node->condition();
auto condition_type = visit(condition);
if (condition->is_AssignmentLocal()) {
// This is not allowed in normal Toit code. If we have an assignment, then
// it's because we moved a declaration out of the look.
// For example:
// `while chunk := read: ...`
// This became:
// chunk := ?
// while chunk = read: ...
auto local = condition->as_AssignmentLocal()->local();
if (local->type().is_any()) {
local->set_type(condition_type);
}
}
if (condition_type.is_none()) {
report_error(node->condition()->range(), "Condition can't be 'none'");
} else if (condition_type != boolean_type_ &&
Expand Down

0 comments on commit 61c0392

Please sign in to comment.