ref: e74148eb539e0809131fe837c2d123b0c295f9ce
parent: f9d4d377fbc039e674b51986b8cbb1486e8eada5
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jan 2 18:19:37 EST 2016
Correctly check for decls without initializers. This turns them into errors. Also fixes a couple that slipped into the code.
--- a/lib/std/hashfuncs.myr
+++ b/lib/std/hashfuncs.myr
@@ -22,7 +22,6 @@
const murmurhash2 : (data : byte[:], seed : uint32 -> uint32)
generic slhash : (sl : @a[:] -> uint32)
- generic tobytes : (sl : @a[:] -> byte[:])
;;
const Seed = 1234
--- a/lib/std/syswrap+posixy.myr
+++ b/lib/std/syswrap+posixy.myr
@@ -68,7 +68,6 @@
pkglocal const getmem : (sz : size -> byte#)
pkglocal const freemem : (p : byte#, sz : size -> void)
pkglocal const curtime : (-> time)
- pkglocal const waitpid : (pid:pid, loc:int32#, opt : int64 -> int64)
;;
/* fd stuff */
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1726,9 +1726,6 @@
unify(st, n, type(st, n), type(st, n->decl.init));
if (n->decl.isconst && !n->decl.init->expr.isconst)
fatal(n, "non-const initializer for \"%s\"", ctxstr(st, n));
- } else {
- if ((n->decl.isconst || n->decl.isgeneric) && !n->decl.isextern)
- fatal(n, "non-extern \"%s\" has no initializer", ctxstr(st, n));
}
}
@@ -1736,8 +1733,16 @@
{
void **k;
size_t n, i;
+ Node *dcl;
Type *t;
+ k = htkeys(s->dcl, &n);
+ for (i = 0; i < n; i++) {
+ dcl = htget(s->dcl, k[i]);
+ tf(st, type(st, dcl));
+ }
+ free(k);
+
k = htkeys(s->ty, &n);
for (i = 0; i < n; i++) {
t = gettype(s, k[i]);
@@ -2098,6 +2103,12 @@
d = getdcl(s, k[i]);
if (d)
d->decl.type = tyfix(st, d, d->decl.type, 0);
+ if (!d->decl.isconst && !d->decl.isgeneric)
+ continue;
+ if (d->decl.trait)
+ continue;
+ if (!d->decl.isimport && !d->decl.isextern && !d->decl.init)
+ fatal(d, "non-extern constant \"%s\" has no initializer", ctxstr(st, d));
}
free(k);
}
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -233,7 +233,9 @@
return NULL;
}
-Stab *getns(Node *file, char *name) { return htget(file->file.ns, name); }
+Stab *getns(Node *file, char *name) {
+ return htget(file->file.ns, name);
+}
static int mergedecl(Node *old, Node *new)
{
--- a/parse/type.c
+++ b/parse/type.c
@@ -854,6 +854,7 @@
func->decl.isgeneric = 1;
func->decl.isconst = 1;
func->decl.isglobl = 1;
+ func->decl.isextern = 1;
lappend(&tr->funcs, &tr->nfuncs, func);
putdcl(st, func);
@@ -873,6 +874,7 @@
func->decl.isgeneric = 1;
func->decl.isconst = 1;
func->decl.isglobl = 1;
+ func->decl.isextern = 1;
lappend(&tr->funcs, &tr->nfuncs, func);
putdcl(st, func);