toit icon indicating copy to clipboard operation
toit copied to clipboard

Compiler doesn't infer type of loop variable for while loops

Open floitsch opened this issue 2 years ago • 1 comments

foo_int -> int?: return 499
foo_string -> string?: return "hello"

main:
  while x := foo_int:
    x = foo_string

  while x/any := foo_int:
    x = foo_string

In the first loop it should infer the type as int and then complain about the foo_string assignment. In the second loop it shouldn't

floitsch avatar Sep 18 '23 16:09 floitsch

This has also implications for warnings that loops are infinite:

while x/int := foo:  // <= should warn that the condition is always true.
  ...

floitsch avatar Oct 10 '23 21:10 floitsch