ref: f7141e2d8ed52e0fb493810ea71adf22fa57a49e
parent: 92c71814af7cba149c2320dbc37627f7da8fa638
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Jan 29 20:43:20 EST 2016
Fix isconstfn. A constant function also needs to be initialized with a literal function.
--- a/6/gen.c
+++ b/6/gen.c
@@ -85,7 +85,7 @@
int isconstfn(Node *n)
{
- Node *d;
+ Node *d, *e;
Type *t;
if (n->type == Nexpr) {
@@ -96,9 +96,16 @@
d = n;
}
t = tybase(decltype(d));
- if (d && d->decl.isconst && d->decl.isglobl && !d->decl.isgeneric)
- return t->type == Tyfunc || t->type == Tycode;
- return 0;
+ if (!d || !d->decl.isconst || !d->decl.isglobl || d->decl.isgeneric)
+ return 0;
+ if (t->type != Tyfunc && t->type != Tycode)
+ return 0;
+ e = d->decl.init;
+ if (e && (exprop(e) != Olit || e->expr.args[0]->lit.littype != Lfunc))
+ return 0;
+ if (!e && !d->decl.isextern && !d->decl.isimport)
+ return 0;
+ return 1;
}
/*