summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-09-22 12:10:15 -0700
committerOri Bernstein <ori@eigenstate.org>2017-09-22 12:10:15 -0700
commit444b77956c15d1895a64891ca16f8313fdb00b9c (patch)
tree73f1e0a2d939916f13512baf8ea58d63010a0d85
parent0de1c881850c5fec2183b2e59cd10b8931cd93a4 (diff)
downloadmc-444b77956c15d1895a64891ca16f8313fdb00b9c.tar.gz
Fix trait lookup for nested pointers.
-rw-r--r--parse/infer.c10
-rw-r--r--test/pkgtrait.myr13
-rw-r--r--test/tests1
3 files changed, 20 insertions, 4 deletions
diff --git a/parse/infer.c b/parse/infer.c
index 83690cc..daa3727 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -895,11 +895,13 @@ tryconstrain(Type *base, Trait *tr)
if (tymatchrank(tm->filter[i], ty) >= 0)
return 1;
}
- if (!tm->sub[ty->type])
- break;
assert(ty->nsub == 1);
- tm = tm->sub[ty->type];
+ if (!ty->sub)
+ break;
ty = ty->sub[0];
+ tm = tm->sub[ty->type];
+ if (!tm)
+ break;
}
if (base->type != Tyname)
break;
@@ -2813,7 +2815,7 @@ addtraittab(Traitmap *m, Trait *tr, Type *ty)
size_t i;
if (!m->sub[ty->type])
- m = mktraitmap();
+ m->sub[ty->type] = mktraitmap();
mm = m->sub[ty->type];
switch (ty->type) {
case Tygeneric:
diff --git a/test/pkgtrait.myr b/test/pkgtrait.myr
new file mode 100644
index 0000000..7825937
--- /dev/null
+++ b/test/pkgtrait.myr
@@ -0,0 +1,13 @@
+use std
+use regex
+
+impl disposable regex.regex# =
+ __dispose__ = {r
+ regex.free(r)
+ }
+;;
+
+const main = {
+ var auto r : regex.regex#
+ r = std.try(regex.compile(".*"))
+}
diff --git a/test/tests b/test/tests
index 07fffaa..3f8342d 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 pkgtrait E 42
B gtrait P '`std.Before '
B emptytrait E 123
B traitimpl P 246,44,meee