pytorch/test/expect/TestJit.test_pretty_printer-loop_use_test.expect
Zachary DeVito 121839b2f8 Fix bugs in assignment to optionals (#25059)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/25059

This fixes the cases where a type annotated with optional cannot
be conditionally assigned to none:

```
x : Optional[int] = 4
if ...:
 x = None
```

Test Plan: Imported from OSS

Differential Revision: D16975166

Pulled By: zdevito

fbshipit-source-id: 5a7a81224d08b9447e1f4d957fcd882091e02f32
2019-08-26 13:47:54 -07:00

10 lines
256 B
Text

def loop_use_test(y: Tensor) -> Tuple[Tensor, Tensor]:
x = torch.add(y, 1, 1)
z = torch.add(x, 5, 1)
z0 = z
y0 = y
_0 = bool(torch.lt(y, 8))
while _0:
y1 = torch.add_(y0, 1, 1)
_0, z0, y0 = bool(torch.lt(y1, 8)), x, y1
return (x, z0)