Make binop coercion look through CoerceT nodes.

This fixes inference for "x = 1 + 1" after int monomorphization.
This commit is contained in:
whitequark 2015-07-14 06:42:09 +03:00
parent ebe243f8d9
commit f417ef31a4
2 changed files with 6 additions and 2 deletions

View File

@ -4,7 +4,6 @@ typing information.
"""
from pythonparser import ast
from pythonparser.algorithm import Visitor as ASTVisitor
class commontyped(ast.commonloc):
"""A mixin for typed AST nodes."""

View File

@ -183,7 +183,12 @@ class Inferencer(algorithm.Visitor):
def _coerce_numeric(self, nodes, map_return=lambda typ: typ):
# See https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex.
node_types = [node.type for node in nodes]
node_types = []
for node in nodes:
if isinstance(node, asttyped.CoerceT):
node_types.append(node.expr.type)
else:
node_types.append(node.type)
if any(map(types.is_var, node_types)): # not enough info yet
return
elif not all(map(builtins.is_numeric, node_types)):