Static analysis tests for type errors with variables.

This commit is contained in:
Dave Halter
2015-06-23 18:04:36 +02:00
parent 64fcbbba79
commit 5d9fff50af
2 changed files with 22 additions and 3 deletions

View File

@@ -4,8 +4,22 @@ if random.choice([0, 1]):
x = ''
else:
x = 1
if x != 1:
x = x.upper()
if random.choice([0, 1]):
y = ''
else:
y = 1
# A simple test
if x != 1:
x.upper()
else:
#! 2 attribute-error
x.upper()
pass
# This operation is wrong, because the types could be different.
#! 6 type-error-operation
z = x + y
# However, here we have correct types.
if type(x) == type(y):
z = x + y