ruby / typeprof

An experimental type-level Ruby interpreter for testing and understanding Ruby code
MIT License
755 stars 84 forks source link

Avoid wrong infinite loop #269

Closed mame closed 1 month ago

mame commented 1 month ago

TypeProf caused an infinite loop under the following situation:

@a = @b[0]
@b = '/' + @a
  1. both @a and @b is untyped
  2. @b is changed to a String because of the second line (String#+)
  3. @a is changed to a String? because of the first line (String#[])
  4. @b is changed to nil because String#+ does not accept String?
  5. go to 2

This change fixes the loop by making String#+ to accept String?.

TODO: it should emit a warning, but it is a bot complex considering the situation where passing Integer | String | nil to the following foo:


def foo: (Integer) -> Integer
       | (String) -> String
``