Rename the field of CoerceT from expr to value.

This commit is contained in:
whitequark 2015-07-16 14:55:23 +03:00
parent e9416f4707
commit 5000f87dfc
2 changed files with 7 additions and 7 deletions

View File

@ -92,4 +92,4 @@ class YieldFromT(ast.YieldFrom, commontyped):
# Novel typed nodes # Novel typed nodes
class CoerceT(ast.expr, commontyped): class CoerceT(ast.expr, commontyped):
_fields = ('expr',) # other_expr deliberately not in _fields _fields = ('value',) # other_value deliberately not in _fields

View File

@ -186,17 +186,17 @@ class Inferencer(algorithm.Visitor):
def visit_CoerceT(self, node): def visit_CoerceT(self, node):
self.generic_visit(node) self.generic_visit(node)
if builtins.is_numeric(node.type) and builtins.is_numeric(node.expr.type): if builtins.is_numeric(node.type) and builtins.is_numeric(node.value.type):
pass pass
else: else:
printer = types.TypePrinter() printer = types.TypePrinter()
note = diagnostic.Diagnostic("note", note = diagnostic.Diagnostic("note",
"expression that required coercion to {typeb}", "expression that required coercion to {typeb}",
{"typeb": printer.name(node.type)}, {"typeb": printer.name(node.type)},
node.other_expr.loc) node.other_value.loc)
diag = diagnostic.Diagnostic("error", diag = diagnostic.Diagnostic("error",
"cannot coerce {typea} to {typeb}", "cannot coerce {typea} to {typeb}",
{"typea": printer.name(node.expr.type), "typeb": printer.name(node.type)}, {"typea": printer.name(node.value.type), "typeb": printer.name(node.type)},
node.loc, notes=[note]) node.loc, notes=[note])
self.engine.process(diag) self.engine.process(diag)
@ -205,9 +205,9 @@ class Inferencer(algorithm.Visitor):
return coerced_node return coerced_node
elif isinstance(coerced_node, asttyped.CoerceT): elif isinstance(coerced_node, asttyped.CoerceT):
node = coerced_node node = coerced_node
node.type, node.other_expr = typ, other_node node.type, node.other_value = typ, other_node
else: else:
node = asttyped.CoerceT(type=typ, expr=coerced_node, other_expr=other_node, node = asttyped.CoerceT(type=typ, value=coerced_node, other_value=other_node,
loc=coerced_node.loc) loc=coerced_node.loc)
self.visit(node) self.visit(node)
return node return node
@ -217,7 +217,7 @@ class Inferencer(algorithm.Visitor):
node_types = [] node_types = []
for node in nodes: for node in nodes:
if isinstance(node, asttyped.CoerceT): if isinstance(node, asttyped.CoerceT):
node_types.append(node.expr.type) node_types.append(node.value.type)
else: else:
node_types.append(node.type) node_types.append(node.type)
if any(map(types.is_var, node_types)): # not enough info yet if any(map(types.is_var, node_types)): # not enough info yet