Commit 60131ac6 authored by Marius Wachtler's avatar Marius Wachtler

Fix compvars error with varargs functions

we were checking if the functions retrieves the exact same number of args as our calling convention requested this failed for varargs.
I encountered this while running test/cpython/test_math.py
parent 88fd6101
......@@ -824,7 +824,9 @@ public:
struct Sig {
std::vector<ConcreteCompilerType*> arg_types;
CompilerType* rtn_type;
int ndefaults;
int ndefaults = 0;
bool takes_varargs = false;
bool takes_kwargs = false;
};
private:
......@@ -847,14 +849,20 @@ public:
RELEASE_ASSERT(!argspec.has_starargs, "");
RELEASE_ASSERT(!argspec.has_kwargs, "");
RELEASE_ASSERT(argspec.num_keywords == 0, "");
RELEASE_ASSERT(!keyword_names || keyword_names->empty() == 0, "");
for (int i = 0; i < sigs.size(); i++) {
Sig* sig = sigs[i];
if (arg_types.size() < sig->arg_types.size() - sig->ndefaults || arg_types.size() > sig->arg_types.size())
int num_normal_args = sig->arg_types.size() - ((sig->takes_varargs ? 1 : 0) + (sig->takes_kwargs ? 1 : 0));
if (arg_types.size() < num_normal_args - sig->ndefaults)
continue;
if (!sig->takes_varargs && arg_types.size() > sig->arg_types.size())
continue;
bool works = true;
for (int j = 0; j < arg_types.size(); j++) {
if (j == num_normal_args)
break;
if (!arg_types[j]->canConvertTo(sig->arg_types[j])) {
works = false;
break;
......@@ -883,6 +891,8 @@ public:
Sig* type_sig = new Sig();
type_sig->rtn_type = fspec->rtn_type;
type_sig->ndefaults = clf->paramspec.num_defaults;
type_sig->takes_varargs = clf->paramspec.takes_varargs;
type_sig->takes_kwargs = clf->paramspec.takes_kwargs;
if (stripfirst) {
assert(fspec->arg_types.size() >= 1);
......
......@@ -173,3 +173,11 @@ class C(object):
def __str__(self):
return "my class"
print "{0}".format(C())
def irgen_error():
for i in range(1):
fail = "test".format()
print fail
fail = "test {0} {1} {2}".format(1, 2, 3)
print fail
irgen_error()
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