-Subproject commit f0007dceb4ce87d3c1882fa385be805fa1c21b62
+Subproject commit 1233e819aee03cc1239f0461cfe6a2bc02b78edb
return t; // unreachable
}
+// trait helpers
+ANN static inline bool has_trait(const Type t, const Symbol trait) {
+ ID_List list = t->info->traits;
+ while(list) {
+ if(list->xid == trait)
+ return true;
+ list = list->next;
+ }
+ return false;
+}
+
+ANN static inline ID_List miss_traits(const Type t, const Specialized_List sl) {
+ ID_List traits = sl->traits;
+ while(traits) {
+ if(!has_trait(t, traits->xid))
+ return traits;
+ traits = traits->next;
+ }
+ return NULL;
+}
typedef enum {
et_void, et_int, et_bool, et_char, et_float,
et_error, et_compound, et_object, et_shred, et_fork, et_event, et_ugen, et_string, et_ptr, et_array, et_gack,
return error;
}
-ANN2(1,2,3) static inline bool trait_nodup(Type t, const Symbol trait, ID_List list) {
+ANN2(1,2) static inline bool trait_nodup(Type t, const Symbol trait, ID_List list) {
bool nodup = true;
do {
while(list) {
return f;
}
-ANN static inline bool has_trait(const Type t, const Symbol trait) {
- ID_List list = t->info->traits;
- while(list) {
- if(list->xid == trait)
- return true;
- list = list->next;
- }
- return false;
-}
-
-ANN static inline bool has_traits(const Type t, const Specialized_List sl) {
- ID_List traits = sl->traits;
- while(traits) {
- if(!has_trait(t, traits->xid))
- return false;
- traits = traits->next;
- }
- return true;
-}
-
ANN static Func _find_template_match(const Env env, const Value v, Exp_Call *const exp) {
DECL_OO(const Func, f, = __find_template_match(env, v, exp));
Type_List tl = exp->tmpl->call;
Specialized_List sl = f->def->base->tmpl->list;
while(tl) {
DECL_OO(const Type, t, = known_type(env, tl->td));
- if(!has_traits(t, sl))
+ if(miss_traits(t, sl))
return NULL;
tl = tl->next;
}
if(tflag(t, tflag_ntmpl) && !td->types)
return t;
struct TemplateScan ts = { .t=t, .td=td };
+Type_List tl = td->types;
+Specialized_List sl = t->info->cdef->base.tmpl->list;
+
+while(tl && sl) {
+ DECL_OO(const Type, t, = known_type(env, tl->td));
+ ID_List missing = miss_traits(t, sl);
+ if(missing) {
+ ERR_O(tl->td->pos, "does not implement requested trait '{/}%s{0}'", s_name(missing->xid));
+ }
+ tl = tl->next;
+ sl = sl->next;
+}
struct Op_Import opi = { .op=insert_symbol("@scan"), .lhs=t, .data=(uintptr_t)&ts, .pos=td->pos };
return op_check(env, &opi);
} else if(td->types)