Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
e6978a4e
Commit
e6978a4e
authored
Sep 17, 2015
by
Delio Brignoli
Committed by
Damien George
Sep 23, 2015
Browse files
py: Fix call args when a stararg is followed by keyword args.
parent
58791416
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/compile.c
View file @
e6978a4e
...
...
@@ -2203,6 +2203,7 @@ STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_ar
int
n_positional
=
n_positional_extra
;
uint
n_keyword
=
0
;
uint
star_flags
=
0
;
mp_parse_node_struct_t
*
star_args_node
=
NULL
,
*
dblstar_args_node
=
NULL
;
for
(
int
i
=
0
;
i
<
n_args
;
i
++
)
{
if
(
MP_PARSE_NODE_IS_STRUCT
(
args
[
i
]))
{
mp_parse_node_struct_t
*
pns_arg
=
(
mp_parse_node_struct_t
*
)
args
[
i
];
...
...
@@ -2212,14 +2213,14 @@ STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_ar
return
;
}
star_flags
|=
MP_EMIT_STAR_FLAG_SINGLE
;
compile_node
(
comp
,
pns_arg
->
nodes
[
0
])
;
star_args_node
=
pns_arg
;
}
else
if
(
MP_PARSE_NODE_STRUCT_KIND
(
pns_arg
)
==
PN_arglist_dbl_star
)
{
if
(
star_flags
&
MP_EMIT_STAR_FLAG_DOUBLE
)
{
compile_syntax_error
(
comp
,
(
mp_parse_node_t
)
pns_arg
,
"can't have multiple **x"
);
return
;
}
star_flags
|=
MP_EMIT_STAR_FLAG_DOUBLE
;
compile_node
(
comp
,
pns_arg
->
nodes
[
0
])
;
dblstar_args_node
=
pns_arg
;
}
else
if
(
MP_PARSE_NODE_STRUCT_KIND
(
pns_arg
)
==
PN_argument
)
{
assert
(
MP_PARSE_NODE_IS_STRUCT
(
pns_arg
->
nodes
[
1
]));
// should always be
mp_parse_node_struct_t
*
pns2
=
(
mp_parse_node_struct_t
*
)
pns_arg
->
nodes
[
1
];
...
...
@@ -2250,6 +2251,14 @@ STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_ar
}
}
// compile the star/double-star arguments if we had them
if
(
star_args_node
!=
NULL
)
{
compile_node
(
comp
,
star_args_node
->
nodes
[
0
]);
}
if
(
dblstar_args_node
!=
NULL
)
{
compile_node
(
comp
,
dblstar_args_node
->
nodes
[
0
]);
}
// emit the function/method call
if
(
is_method_call
)
{
EMIT_ARG
(
call_method
,
n_positional
,
n_keyword
,
star_flags
);
...
...
tests/basics/fun_kwvarargs.py
View file @
e6978a4e
...
...
@@ -17,3 +17,15 @@ f3(1)
f3
(
1
,
2
)
f3
(
1
,
b
=
2
)
f3
(
1
,
2
,
b
=
3
)
def
f4
(
*
vargs
,
**
kwargs
):
print
(
vargs
,
kwargs
)
f4
(
*
(
1
,
2
))
f4
(
kw_arg
=
3
)
f4
(
*
(
1
,
2
),
kw_arg
=
3
)
# test evaluation order of arguments (in CPy 3.4 it's actually backwards)
def
print_ret
(
x
):
print
(
x
)
return
x
f4
(
*
print_ret
([
'a'
,
'b'
]),
kw_arg
=
print_ret
(
None
))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment