shithub: mc

Download patch

ref: d4862853ca810b97d1adc2944f32975fd4a5018f
parent: b7cd6588a862680434445e53f27125e43d76a4af
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Oct 21 15:49:23 EDT 2017

Don't bungle trait merging and exporting.

--- a/parse/stab.c
+++ b/parse/stab.c
@@ -523,9 +523,12 @@
 
 	st = findstab(st, n);
 	t = gettrait(st, n);
-	if (t && !mergetrait(t, c))
+	if (t) {
+		if (mergetrait(t, c))
+			return;
 		fatal(n, "trait %s already defined on %s:%d",
 			namestr(n), fname(t->loc), lnum(t->loc));
+	}
 	ty = gettype(st, n);
 	if (ty)
 		fatal(n, "trait %s defined as a type on %s:%d",
--- a/parse/use.c
+++ b/parse/use.c
@@ -1168,6 +1168,7 @@
 {
 	Stab *st;
 	void **k;
+	Trait *tr;
 	Node *s, *u;
 	size_t i, n;
 
@@ -1211,14 +1212,17 @@
 		}
 	}
 
-	for (i = 0; i < ntraittab; i++) {
-		if (i < Ntraits || i != traittab[i]->uid)
+	k = htkeys(st->tr, &n);
+	for (i = 0; i < n; i++) {
+		tr = gettrait(st, k[i]);
+		if (tr->uid < Ntraits)
 			continue;
-		if (traittab[i]->vis == Visexport || traittab[i]->vis == Vishidden) {
+		if (tr->vis == Visexport || tr->vis == Vishidden) {
 			wrbyte(f, 'R');
-			traitpickle(f, traittab[i]);
+			traitpickle(f, tr);
 		}
 	}
+	free(k);
 
 	k = htkeys(st->impl, &n);
 	for (i = 0; i < n; i++) {