summaryrefslogtreecommitdiff
path: root/Cython/Compiler/ParseTreeTransforms.py
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2017-07-31 18:20:01 +0200
committerStefan Behnel <stefan_ml@behnel.de>2017-07-31 18:20:01 +0200
commit91f2c2ed6dec088d4f3f14b582fa2908149abc24 (patch)
tree1885f3bf0b34e9d25fc36f9f8abcd760797524c2 /Cython/Compiler/ParseTreeTransforms.py
parent4b61de606e05fb9c9a7eb4cdf3e897a4740e1f27 (diff)
downloadcython-91f2c2ed6dec088d4f3f14b582fa2908149abc24.tar.gz
Fix a compiler crash when looking up cython.view.array() as a callable function with non-trivial keyword arguments.
Closes #1598.
Diffstat (limited to 'Cython/Compiler/ParseTreeTransforms.py')
-rw-r--r--Cython/Compiler/ParseTreeTransforms.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py
index e7ba2c55b..da94a0171 100644
--- a/Cython/Compiler/ParseTreeTransforms.py
+++ b/Cython/Compiler/ParseTreeTransforms.py
@@ -3020,22 +3020,22 @@ class TransformBuiltinMethods(EnvTransform):
def visit_GeneralCallNode(self, node):
function = node.function.as_cython_attribute()
- if function:
+ if function == u'cast':
+ # NOTE: assuming simple tuple/dict nodes for positional_args and keyword_args
args = node.positional_args.args
kwargs = node.keyword_args.compile_time_value(None)
- if function == u'cast':
- if (len(args) != 2 or len(kwargs) > 1 or
- (len(kwargs) == 1 and 'typecheck' not in kwargs)):
- error(node.function.pos,
- u"cast() takes exactly two arguments and an optional typecheck keyword")
+ if (len(args) != 2 or len(kwargs) > 1 or
+ (len(kwargs) == 1 and 'typecheck' not in kwargs)):
+ error(node.function.pos,
+ u"cast() takes exactly two arguments and an optional typecheck keyword")
+ else:
+ type = args[0].analyse_as_type(self.current_env())
+ if type:
+ typecheck = kwargs.get('typecheck', False)
+ node = ExprNodes.TypecastNode(
+ node.function.pos, type=type, operand=args[1], typecheck=typecheck)
else:
- type = args[0].analyse_as_type(self.current_env())
- if type:
- typecheck = kwargs.get('typecheck', False)
- node = ExprNodes.TypecastNode(
- node.function.pos, type=type, operand=args[1], typecheck=typecheck)
- else:
- error(args[0].pos, "Not a type")
+ error(args[0].pos, "Not a type")
self.visitchildren(node)
return node