From f417ef31a4971f460008e6ad2e4ab7a6322284ef Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 14 Jul 2015 06:42:09 +0300 Subject: [PATCH] Make binop coercion look through CoerceT nodes. This fixes inference for "x = 1 + 1" after int monomorphization. --- artiq/compiler/asttyped.py | 1 - artiq/compiler/transforms/inferencer.py | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/artiq/compiler/asttyped.py b/artiq/compiler/asttyped.py index 5184c7401..f29b59d4a 100644 --- a/artiq/compiler/asttyped.py +++ b/artiq/compiler/asttyped.py @@ -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.""" diff --git a/artiq/compiler/transforms/inferencer.py b/artiq/compiler/transforms/inferencer.py index 37de32532..c06453601 100644 --- a/artiq/compiler/transforms/inferencer.py +++ b/artiq/compiler/transforms/inferencer.py @@ -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)):