fix list type unification (#17424)
authorElias Ellison <eellison@fb.com>
Mon, 25 Feb 2019 21:26:49 +0000 (13:26 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Mon, 25 Feb 2019 21:34:50 +0000 (13:34 -0800)
commitb0b7541ca4ddfa2f5967e17dac01f5bf471b8566
treeefdbf0f4beff961e2401fd06c3e262d5a7cbcb6b
parentb527055fcf4b808cc4d586e27b76c5d91daa8bf6
fix list type unification (#17424)

Summary:
Previously we were unifying the types of lists across if block outputs. This now fails with Optional subtyping because two types which can be unified have different runtime representations.
```

            torch.jit.script
            def list_optional_fails(x):
                # type: (bool) -> Optional[int]
                if x:
                    y = [1]
                else:
                    y = [None]
                return y[0]

```
the indexing op will expect y to be a generic list, but it will find an intlist.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/17424

Differential Revision: D14210903

Pulled By: eellison

fbshipit-source-id: 4b8b26ba2e7e5bebf617e40316475f91e9109cc2
aten/src/ATen/core/type.cpp
test/test_jit.py