pfnet-research / chainer-compiler

Experimental toolchain to compile and run Chainer models
MIT License
112 stars 23 forks source link

Add type guard for optional types #814

Closed momohatt closed 4 years ago

momohatt commented 4 years ago

This PR implements basic type guard (like the one in TypeScript) for optional types. It narrows down the type of the variable being tested in the if statement as follows.

# x : optional(int)
if x is None:
    # x : NoneType
else:
    # x : int
# x : NoneType
if x is None:
    # x : NoneType
else:
    # x : a (fresh TyVar)
# x : int
if x is None:
    # x : NoneType
else:
    # x : int
shinh commented 4 years ago

/test

pfn-ci-bot commented 4 years ago

Successfully created a job for commit 91ce49d:

shinh commented 4 years ago

lgtm!