shithub: mc

Download patch

ref: 034acf0ceac80411fc85bbd4cc9e237d26a6e36c
parent: 5456cd41e88678aec8b594f6a1488d3f388d99ed
author: Ori Bernstein <[email protected]>
date: Tue Dec 5 17:30:09 EST 2017

Error correctly when a const has no init.

	This happens with externs.

--- a/mi/match.c
+++ b/mi/match.c
@@ -275,12 +275,6 @@
 }
 
 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 @@
 {
 	int ret;
 	Node *dcl;
+	Type *ty;
 
 	pat = fold(pat, 1);
 	ret = 0;
@@ -666,8 +661,11 @@
 	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);