summaryrefslogtreecommitdiff
path: root/mi
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-12-05 22:30:09 -0800
committerOri Bernstein <ori@eigenstate.org>2017-12-05 22:30:09 -0800
commit034acf0ceac80411fc85bbd4cc9e237d26a6e36c (patch)
tree97cec137137eaf802d61d3c885a9f21001ca8995 /mi
parent5456cd41e88678aec8b594f6a1488d3f388d99ed (diff)
downloadmc-034acf0ceac80411fc85bbd4cc9e237d26a6e36c.tar.gz
Error correctly when a const has no init.
This happens with externs.
Diffstat (limited to 'mi')
-rw-r--r--mi/match.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/mi/match.c b/mi/match.c
index 0a24cc4..a904c60 100644
--- a/mi/match.c
+++ b/mi/match.c
@@ -275,12 +275,6 @@ isnonrecursive(Dtree *dt, Type *ty)
}
static int
-ismatchable(Type *ty)
-{
- return ty->type != Tyfunc && ty->type != Tycode && ty->type != Tyvalist;
-}
-
-static int
addwildrec(Srcloc loc, Type *ty, Dtree *start, Dtree *accept, Dtree ***end, size_t *nend)
{
Dtree *next, **last, **tail;
@@ -659,6 +653,7 @@ addpat(Node *pat, Node *val, Dtree *start, Dtree *accept, Node ***cap, size_t *n
{
int ret;
Node *dcl;
+ Type *ty;
pat = fold(pat, 1);
ret = 0;
@@ -666,8 +661,11 @@ addpat(Node *pat, Node *val, Dtree *start, Dtree *accept, Node ***cap, size_t *n
case Ovar:
dcl = decls[pat->expr.did];
if (dcl->decl.isconst) {
- if (!ismatchable(decltype(dcl)))
- fatal(dcl, "matching unmatchable type %s", tystr(decltype(dcl)));
+ ty = decltype(dcl);
+ if (ty->type == Tyfunc || ty->type == Tycode || ty->type == Tyvalist)
+ fatal(dcl, "bad pattern %s:%s: unmatchable type", declname(dcl), tystr(ty));
+ if (!dcl->decl.init)
+ fatal(dcl, "bad pattern %s:%s: missing initializer", declname(dcl), tystr(ty));
ret = addpat(dcl->decl.init, val, start, accept, cap, ncap, end, nend);
} else {
ret = addwild(pat, val, start, accept, cap, ncap, end, nend);