Commit 927e1a4d authored by Stefan Behnel's avatar Stefan Behnel

match simple keyword arguments that are passed into cdef function calls out-of-order

parent af7fa72e
......@@ -4380,8 +4380,8 @@ class GeneralCallNode(CallNode):
unmatched_args = declared_args[len(args):]
matched_kwargs = set()
args = list(args)
# TODO: match keywords out-of-order and move values
# into ordered temps if necessary
# match keywords that are passed in order
for decl_arg, arg in zip(unmatched_args, kwargs.key_value_pairs):
name = arg.key.value
if name in matched_pos_args:
......@@ -4392,6 +4392,25 @@ class GeneralCallNode(CallNode):
args.append(arg.value)
else:
break
# match simple keyword arguments that are passed out of order
if len(kwargs.key_value_pairs) > len(matched_kwargs):
unmatched_args = declared_args[len(args):]
keywords = dict([ (arg.key.value, arg.value)
for arg in kwargs.key_value_pairs ])
for decl_arg in unmatched_args:
name = decl_arg.name
arg_value = keywords.get(name)
if arg_value and arg_value.is_simple():
matched_kwargs.add(name)
args.append(arg_value)
else:
# first missing keyword argument
break
# TODO: match keywords out-of-order and move values
# into ordered temps if necessary
if not matched_kwargs:
return
self.positional_args.args = args
......
......@@ -33,7 +33,6 @@ def cfunc_some_keywords():
return cfunc(1, 2, c=3, d=4)
'''
@cython.test_fail_if_path_exists('//GeneralCallNode')
@cython.test_assert_path_exists('//SimpleCallNode')
def cfunc_some_keywords_unordered():
......@@ -41,8 +40,10 @@ def cfunc_some_keywords_unordered():
>>> cfunc_some_keywords_unordered()
(1, 2, 3, 4)
"""
return cfunc(1, 2, d=4, d=3)
return cfunc(1, 2, d=4, c=3)
'''
@cython.test_fail_if_path_exists('//GeneralCallNode')
@cython.test_assert_path_exists('//SimpleCallNode')
def cfunc_some_keywords_unordered_sideeffect():
......@@ -53,7 +54,7 @@ def cfunc_some_keywords_unordered_sideeffect():
>>> sideeffect
[4, 3]
"""
return cfunc(1, 2, d=side_effect(4), d=side_effect(3))
return cfunc(1, 2, d=side_effect(4), c=side_effect(3))
'''
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment