shithub: mc

Download patch

ref: 433606f675efdaa466b7e9ab8adb257999af5ae6
parent: 548ce5467e98c95e545be3fd021da014798a942d
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Aug 13 14:17:46 EDT 2017

If a trait is specialized over a generic, it's generic too.

--- a/mk/c.mk
+++ b/mk/c.mk
@@ -9,7 +9,7 @@
 _LIBPATHS=$(addprefix -l, $(patsubst lib%.a,%,$(notdir $(DEPS)))) $(_PCLIBS)
 
 # yeah, I should probably remove -Werror, but it's nice for developing alone.
-CFLAGS += -Wall -Werror -Wno-unused-parameter -Wno-missing-field-initializers -Wno-sign-compare -Wno-char-subscripts -g -O3
+CFLAGS += -Wall -Werror -Wno-unused-parameter -Wno-missing-field-initializers -Wno-sign-compare -Wno-char-subscripts -g -O0
 CFLAGS += -MMD -MP -MF .deps/$(subst /,-,$*).d
 
 LIB ?= $(INSTLIB)
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1740,6 +1740,7 @@
 	Type *ty;
 	Trait *t;
 	size_t i, j;
+	int generic;
 
 	t = gettrait(curstab(), n->impl.traitname);
 	if (!t)
@@ -1787,6 +1788,10 @@
 		ty = tyspecialize(type(proto), subst, delayed, NULL);
 		substfree(subst);
 
+		generic = hasparams(ty);
+		if (generic)
+			ingeneric++;
+
 		inferdecl(dcl);
 		unify(n, type(dcl), ty);
 
@@ -1812,6 +1817,9 @@
 					tystr(ty));
 		dcl->decl.vis = t->vis;
 		lappend(&impldecl, &nimpldecl, dcl);
+
+		if (generic)
+			ingeneric--;
 	}
 	popenv(n->impl.type->env);
 }
--- /dev/null
+++ b/test/gtrait.myr
@@ -1,0 +1,15 @@
+use std
+
+trait comparable @a =
+	cmp	: (a : @a, b : @a -> std.order)
+;;
+
+impl comparable @a::numeric =
+	cmp = {a, b
+		-> std.numcmp(a, b)
+	}
+;;
+
+const main = {
+	std.put("{}", cmp(1, 2))
+}
--- a/test/tests
+++ b/test/tests
@@ -86,6 +86,7 @@
 B generic	E	42
 B genericval	E	42
 B trait-builtin	E	42
+B gtrait	P	'`std.Before '
 B emptytrait	E	123
 B traitimpl	P	246,44,meee
 # B compoundimpl	P	intptr,charptr BUGGERED