shithub: mc

Download patch

ref: 9a2f63d47a96bf522e6c5d39e215b2e6a9e600c7
parent: c5245eaa80064b77186fa286f8e5e8bca73309ab
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Jul 28 19:36:36 EDT 2017

Fix error message for generics in non-generic decls.

--- a/parse/infer.c
+++ b/parse/infer.c
@@ -734,7 +734,9 @@
 {
 	if (!a->traits || bscount(a->traits) == 0)
 		return 1;
-	return bsissubset(a->traits, b->traits);
+	if (b->traits)
+		return bsissubset(a->traits, b->traits);
+	return 0;
 }
 
 static void
@@ -1297,7 +1299,6 @@
 	 *
 	 * To make it compile, for now, we just bind the types in here.
 	 */
-	//tybindall(uc->utype);
 	t = tysubst(tf(uc->utype), uc->utype);
 	uc = tybase(t)->udecls[uc->id];
 	if (uc->etype) {
@@ -1306,7 +1307,6 @@
 		*isconst = n->expr.args[1]->expr.isconst;
 	}
 	settype(n, delayeducon(t));
-	//tyunbind();
 }
 
 static void
@@ -1623,10 +1623,7 @@
 		   infersub(n, ret, sawret, &isconst);
 		   switch (args[0]->lit.littype) {
 		   case Lfunc:
-			   //tybindall(args[0]->lit.fnval->func.type);
 			   infernode(&args[0]->lit.fnval, NULL, NULL);
-			   //tyunbind();
-
 			   /* FIXME: env capture means this is non-const */
 			   n->expr.isconst = 1;
 			   break;
@@ -1876,7 +1873,7 @@
 		setsuperenv(n->decl.env, curenv());
 		pushenv(n->decl.env);
 		inferdecl(n);
-		if (type(n)->type == Typaram && !ingeneric)
+		if (hasparams(type(n)) && !ingeneric)
 			fatal(n, "generic type %s in non-generic near %s", tystr(type(n)),
 					ctxstr(n));
 		popenv(n->decl.env);
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -419,8 +419,6 @@
 Tyenv *curenv(void);
 void pushenv(Tyenv *e);
 void popenv(Tyenv *e);
-void _tybind(Tyenv *e, Type *t);
-void _bind(Tyenv *e, Node *n);
 
 /* type creation */
 void tyinit(Stab *st); /* sets up built in types */
--- a/parse/type.c
+++ b/parse/type.c
@@ -417,7 +417,7 @@
 		return 0;
 	bsput(visited, t->tid);
 	switch (t->type) {
-	case Typaram:
+	case Typaram:	return 1;
 	case Tygeneric: return 1;
 	case Tyname:
 			for (i = 0; i < t->narg; i++)