From 6087772263905d6055d58bcd817e07804b6d83b0 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Thu, 16 Mar 2023 16:12:40 -0500 Subject: [PATCH] bugfix: segfault in weird case; added: overload to `iter.as_iter` --- compiler/src/astnodes.c | 4 ++-- core/container/iter.onyx | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/compiler/src/astnodes.c b/compiler/src/astnodes.c index 3776e08e..f53943e8 100644 --- a/compiler/src/astnodes.c +++ b/compiler/src/astnodes.c @@ -860,7 +860,7 @@ TypeMatch unify_node_and_type_(AstTyped** pnode, Type* type, b32 permanent) { // other uses of checking polymorphic structures against // actual nodes strictly forbidden. if (type->kind == Type_Kind_PolyStruct) { - if (node_type->kind == Type_Kind_Struct) { + if (node_type && node_type->kind == Type_Kind_Struct) { if (node_type->Struct.constructed_from->type_id == type->id) { return TYPE_MATCH_SUCCESS; } @@ -871,7 +871,7 @@ TypeMatch unify_node_and_type_(AstTyped** pnode, Type* type, b32 permanent) { // This case enables to ability to have less values on the // left hand side of an assignment than what the right hand // side call would be returning. - if (node_type->kind == Type_Kind_Compound) { + if (node_type && node_type->kind == Type_Kind_Compound) { AstCall *call = get_call_expr_from_node((AstNode *) node); if (!call) return TYPE_MATCH_FAILED; diff --git a/core/container/iter.onyx b/core/container/iter.onyx index e84d8ba4..bc08cf93 100644 --- a/core/container/iter.onyx +++ b/core/container/iter.onyx @@ -454,6 +454,20 @@ from_array :: (arr: [] $T/type_is_struct) => generator( } ); +#overload +from_array :: (arr: [] $T, by_pointer: bool) => generator( + &.{ data = arr.data, count = arr.count, current = 0 }, + + ctx => { + if ctx.current < ctx.count { + defer ctx.current += 1; + return &ctx.data[ctx.current], true; + } + + return null, false; + } +); + #overload from_array :: (arr: [] $T) => generator( &.{ data = arr.data, count = arr.count, current = 0 }, -- 2.25.1