bugfix: segfault in weird case; added: overload to `iter.as_iter`
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 16 Mar 2023 21:12:40 +0000 (16:12 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 16 Mar 2023 21:12:40 +0000 (16:12 -0500)
compiler/src/astnodes.c
core/container/iter.onyx

index 3776e08e02da48d3b556a0580154d99fdb9fde5e..f53943e856f67ee3c25a6a18e0011eddb1092835 100644 (file)
@@ -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;
 
index e84d8ba421a43e8cf337307bec869859dd7a8bec..bc08cf930e455122004939600cd84c65a2b20b47 100644 (file)
@@ -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 },