Fix Python default args when using kwargs

Recent default arg handling fixes didn't fix the case when kwargs is turned on
This commit is contained in:
William S Fulton 2015-01-15 07:54:36 +00:00
commit afba5b755a
3 changed files with 37 additions and 24 deletions

View file

@ -79,9 +79,9 @@
static const size_type hello = 3;
};
int rfoo( const size_type& x = Hello::hello, const Hello& y = Hello() )
int rfoo( int n = 0, const size_type& x = Hello::hello, const Hello& y = Hello() )
{
return x;
return n - x;
}
%}
%{

View file

@ -51,7 +51,7 @@ if foo_fn(b=2) != 3:
raise RuntimeError
#Funtions with keywords
#Functions with keywords
if foo_kw(_from=2) != 4:
raise RuntimeError
@ -65,3 +65,17 @@ if foo_mm(min=2) != 4:
if foo_mm(max=3) != 4:
raise RuntimeError
#Default args with references
if rfoo(n=123) != 120:
raise RuntimeError
if rfoo(x=10) != -10:
raise RuntimeError
if rfoo(n=11, x=22) != -11:
raise RuntimeError
if rfoo(x=11, n=22) != 11:
raise RuntimeError

View file

@ -1976,32 +1976,31 @@ public:
bool is_representable_as_pyargs(Node *n) {
bool is_representable = true;
if (Getattr(n, "sym:overloaded")) {
ParmList *plist = CopyParmList(Getattr(n, "parms"));
Parm *p;
Parm *pnext;
ParmList *plist = CopyParmList(Getattr(n, "parms"));
Parm *p;
Parm *pnext;
for (p = plist; p; p = pnext) {
pnext = NIL;
String *tm = Getattr(p, "tmap:in");
if (tm) {
pnext = Getattr(p, "tmap:in:next");
if (checkAttribute(p, "tmap:in:numinputs", "0")) {
continue;
}
for (p = plist; p; p = pnext) {
pnext = NIL;
String *tm = Getattr(p, "tmap:in");
if (tm) {
pnext = Getattr(p, "tmap:in:next");
if (checkAttribute(p, "tmap:in:numinputs", "0")) {
continue;
}
if (!pnext) {
pnext = nextSibling(p);
}
if (String *value = Getattr(p, "value")) {
String *type = Getattr(p, "type");
if (!convertValue(value, type)) {
is_representable = false;
break;
}
}
if (!pnext) {
pnext = nextSibling(p);
}
if (String *value = Getattr(p, "value")) {
String *type = Getattr(p, "type");
if (!convertValue(value, type)) {
is_representable = false;
break;
}
}
}
return is_representable;
}