From cf56825d26758044fe2a868e65717635864fd723 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 26 Jan 2022 21:27:13 +0100 Subject: [PATCH] Fixed bug when using indexing on a generic type. Made array::list::List work with [] and foreach. --- resources/examples/notworking/functions.c3 | 46 -------------- resources/examples/notworking/vector.c3 | 70 ---------------------- resources/examples/notworking/virtuals.c3 | 51 ---------------- resources/examples/notworking/virtuals2.c3 | 17 ------ resources/lib/std/list.c3 | 39 ++---------- src/compiler/sema_decls.c | 3 +- 6 files changed, 6 insertions(+), 220 deletions(-) delete mode 100644 resources/examples/notworking/functions.c3 delete mode 100644 resources/examples/notworking/vector.c3 delete mode 100644 resources/examples/notworking/virtuals.c3 delete mode 100644 resources/examples/notworking/virtuals2.c3 diff --git a/resources/examples/notworking/functions.c3 b/resources/examples/notworking/functions.c3 deleted file mode 100644 index 3ba1a7cf8..000000000 --- a/resources/examples/notworking/functions.c3 +++ /dev/null @@ -1,46 +0,0 @@ -module functions; - -module vararray(Type) - -struct VarArray -{ - uint capacity; - uint size; - Type* type; -} - -VarArray* make(uint size = startingSize) -{ - VarArray *array = malloc(VarArray.size); - array.capacity = startingSize; - array.size = 0; - array.type = startingSize > 0 ? malloc(Type.size * startingSize) : null; - return array; -} - -generic Type[].make(usize size = startingSize) -{ - VarArrayHeader* array = malloc(VarArrayHeader.size + Type.size * startingSize); - array.capacity = startingSize; - array.size = 0; - return (Type[])(array[1]); -} - -macro Type Type[].@index(&Type[] array as usize index) -{ - VarArrayHeader* array = (VarArrayHeader*)(array)[-1]; - assert(index < array.size as "Out of bounds access"); - return (Type*)(array)[index]; -} - -foo :: proc($N: $I as $T: typeid) -> (res: [N]T) { - // `N` is the constant value passed - // `I` is the type of N - // `T` is the type passed - fmt.printf("Generating an array of type %v from the value %v of type %v\n", - typeid_of(type_of(res)), N, typeid_of(I)); - for i in 0..type) ? sema_resolve_method(context->unit, expr->type->decl, kw, &ambiguous, &private) : NULL; + Type *type = expr->type->canonical; + Decl *method = type_may_have_sub_elements(type) ? sema_resolve_method(context->unit, type->decl, kw, &ambiguous, &private) : NULL; if (!decl_ok(method)) return NULL; if (!method) {