summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-08-13 18:17:46 -0700
committerOri Bernstein <ori@eigenstate.org>2017-08-13 18:24:50 -0700
commit433606f675efdaa466b7e9ab8adb257999af5ae6 (patch)
tree2708d45d3f391bed7a99da3bd30502993cd5fdde
parent548ce5467e98c95e545be3fd021da014798a942d (diff)
downloadmc-433606f675efdaa466b7e9ab8adb257999af5ae6.tar.gz
If a trait is specialized over a generic, it's generic too.
-rw-r--r--mk/c.mk2
-rw-r--r--parse/infer.c8
-rw-r--r--test/gtrait.myr15
-rw-r--r--test/tests1
4 files changed, 25 insertions, 1 deletions
diff --git a/mk/c.mk b/mk/c.mk
index 764846f..25167bc 100644
--- a/mk/c.mk
+++ b/mk/c.mk
@@ -9,7 +9,7 @@ _LIBINCPATHS=$(addprefix -I, $(dir $(DEPS))) $(_PCHDRS)
_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)
diff --git a/parse/infer.c b/parse/infer.c
index 04f7fc6..e29dd80 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1740,6 +1740,7 @@ specializeimpl(Node *n)
Type *ty;
Trait *t;
size_t i, j;
+ int generic;
t = gettrait(curstab(), n->impl.traitname);
if (!t)
@@ -1787,6 +1788,10 @@ specializeimpl(Node *n)
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 @@ specializeimpl(Node *n)
tystr(ty));
dcl->decl.vis = t->vis;
lappend(&impldecl, &nimpldecl, dcl);
+
+ if (generic)
+ ingeneric--;
}
popenv(n->impl.type->env);
}
diff --git a/test/gtrait.myr b/test/gtrait.myr
new file mode 100644
index 0000000..5131ccc
--- /dev/null
+++ b/test/gtrait.myr
@@ -0,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))
+}
diff --git a/test/tests b/test/tests
index fcd058c..07fffaa 100644
--- a/test/tests
+++ b/test/tests
@@ -86,6 +86,7 @@ B multistr E 0
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