Merge remote-tracking branch 'origin/topic/zeke/expire-func'

* origin/topic/zeke/expire-func:
  Ignore abs-path in test.
  Report argument # type check failed on.
  Update test baseline.
  Improve func arg type checking.
  &expire_func(table, arg1, arg2, ...) + type checking.
This commit is contained in:
Johanna Amann 2019-07-22 11:28:30 -07:00
commit 3159577821
8 changed files with 119 additions and 25 deletions

View file

@ -2306,24 +2306,45 @@ double TableVal::CallExpireFunc(Val* idx)
return 0;
}
const Func* f = vf->AsFunc();
val_list vl { Ref() };
// Flatten lists of a single element.
if ( idx->Type()->Tag() == TYPE_LIST &&
idx->AsListVal()->Length() == 1 )
const auto func_args = f->FType()->ArgTypes()->Types();
// backwards compatibility with idx: any idiom
bool any_idiom = func_args->length() == 2 && func_args->back()->Tag() == TYPE_ANY;
if ( idx->Type()->Tag() == TYPE_LIST )
{
Val* old = idx;
idx = idx->AsListVal()->Index(0);
idx->Ref();
Unref(old);
if ( ! any_idiom )
{
const val_list* vl0 = idx->AsListVal()->Vals();
for ( const auto& v : *idx->AsListVal()->Vals() )
vl.append(v->Ref());
}
else
{
ListVal* idx_list = idx->AsListVal();
// Flatten if only one element
if (idx_list->Length() == 1)
idx = idx_list->Index(0);
vl.append(idx->Ref());
}
}
else
{
vl.append(idx->Ref());
}
val_list vl{Ref(), idx};
Val* vs = vf->AsFunc()->Call(&vl);
Val* result = 0;
if ( vs )
result = f->Call(&vl);
if ( result )
{
secs = vs->AsInterval();
Unref(vs);
secs = result->AsInterval();
Unref(result);
}
Unref(vf);