Closed carljm closed 2 years ago
Here's another program that might be affected by a fix
(The test is from Lib/test/test_compiler/test_static/tests.py)
def test_assign_while_returns_but_assigns_first(self):
codestr = """
from typing import Optional
def f(x: Optional[int]) -> int:
y: Optional[int] = 1
while x is None:
y = None
return 1
return y
"""
self.compile(codestr, modname="foo")
Thanks @LuKC1024 ! I think this program will be fine; it does not involve implicit-None-return anywhere so it should not be affected by the fix for #62, and it does not involve a definitely-infinite loop, so it should not be impacted by whatever is done for this issue.
Are you seeing an issue related to our handling of this program in your model?
Hi Carl. If it's not affected, that's great. The model has trouble with this program because the type-checker needs to know y = None
won’t be effective after the while-loop exits (because the function has returned before that).
Right. The SP type checker does detect if a loop unconditionally terminates, and in that case ignores its local-type effects after the loop.
Fixed by 49e44ef93d03259e3a0c45b0a73894ff81a383c0
The fix for #62 will probably lead us to reject this program:
In order to fix this, we need to understand that the
while
loop does not terminate (unless there's abreak
) and narrow the types in the code following the loop accordingly.