Pyrefly forgets (?) a type in the middle of a function definition
Describe the Bug
I assume this must be a known problem but I don't even know how to find it, or reduce this repro further
See sandbox link. Why is an error reported for func but not func2?
Sandbox Link
https://pyrefly.org/sandbox/?code=EYQwTgXABAzgLmKBeKAiUZUCgsBMCmAZlIQK4B2AxgBQCUEWUTJA9i9PIgD5QByL5fMj4D8jZuKaEWiAB5QAluSgBtALoNmW1ogCei5es3aTABxAwYOLaABeHBMOksoMqBhwFiZKgCY6xlJsDtwigsL8gtbM0nIGqhqS2uaW0Ux2IU5srogYQA
(Only applicable for extension issues) IDE Information
No response
I have another example of what might be the same underlying bug?
https://pyrefly.org/sandbox/?code=CYUwZgBGD20BQDcCGAbAXBAlgOwC4QB8IA5abEASggFoA+LPNAKAla0mRSwGcSyRmbIRFwAnAJ6Dh00SFwBXUdggBGFtIggAHgGMQAB1xSNbWQqUQATOtZnFyzkyahIMaJcSoMOfEVLkqOgYjG3YITh4+cmNhMUlQkzsLNRMwHFQUeJMhJOVrHLl7cNQgA
I can submit this separately if preferred
This is super weird! Let me investigate!
These bugs are quite different. Breaking down the second:
def foo(val: int | None, b: bool) -> int:
if val is None:
if b:
return 1
else:
return 2
return val
We get this wrong too, failing to infer the return type.
I've fixed the second issue. So no need to split it up.
The first bug is just that we create a Var, and when doing or short circuit stuff we forgot to expand Var. Doing that solves the issue.