bugfix with macros with auto-return type
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 29 Aug 2021 04:05:07 +0000 (23:05 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 29 Aug 2021 04:05:07 +0000 (23:05 -0500)
bin/onyx
docs/bugs
src/onyxchecker.c
src/onyxsymres.c
src/onyxutils.c
tests/bugs/macro_auto_return_not_resolved [new file with mode: 0644]
tests/bugs/macro_auto_return_not_resolved.onyx [new file with mode: 0644]

index 30b2a89058ad1c5a5c3ee41d721357c527e38db3..3fa5c3739fd972ebd0167ddc97d574980ce6a190 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index c77390864d936172a39a223e4b44711c70deaba8..e3ead4575f4cf034e8f26fd939f970d647dbc82c 100644 (file)
--- a/docs/bugs
+++ b/docs/bugs
@@ -1,5 +1,13 @@
 List of known bugs:
 
+[ ] macros cannot use 'use'.
+
+    Vec2 :: struct { x, y : f32; }
+
+    foo :: macro (use v: Vec2) {
+        println(x); // Doesn't work
+    }
+
 [X] macros are not allowed at the expression level. This is not necessarily a bug, but does
     bring many complications to the table about how resolve this. Current solution is to
     turn expression macros (macros that specify a return value) into a `do` expression.
index ce564b16429f5f97dbf18095611d2bd4de7b407d..d581a2dc93aff92a08cbb10d97c06e8ee69626e7 100644 (file)
@@ -579,7 +579,7 @@ CheckStatus check_call(AstCall** pcall) {
             filename->kind  = Ast_Kind_StrLit;
             filename->token = str_token;
             filename->addr  = 0;
-            
+
             add_entities_for_node(NULL, (AstNode *) filename, NULL, NULL);
             callsite->filename = filename;
 
@@ -616,7 +616,7 @@ CheckStatus check_call(AstCall** pcall) {
 
     call->va_kind = VA_Kind_Not_VA;
     call->type = callee->type->Function.return_type;
-    if (call->type == &type_auto_return) {
+    if (call->type == &type_auto_return && call->callee->kind != Ast_Kind_Macro) {
         YIELD(call->token->pos, "Waiting for auto-return type to be solved.");
     }
 
@@ -1959,7 +1959,7 @@ CheckStatus check_overloaded_function(AstOverloadedFunction* func) {
 
         if (node->kind == Ast_Kind_Function) {
             AstFunction* func = (AstFunction *) node;
-            
+
             if (func->entity_header && func->entity_header->state <= Entity_State_Check_Types) {
                 done = 0;
             }
index 0bc9b32a801147408db3963679eaf8623fd6649a..01d86ee55f72e49a2d00c06ef09aaab8bbdb22df 100644 (file)
@@ -1058,23 +1058,16 @@ static SymresStatus symres_memres(AstMemRes** memres) {
 
 static SymresStatus symres_struct_defaults(AstType* t) {
     if (t->kind != Ast_Kind_Struct_Type) return Symres_Error;
-    
+
     AstStructType* st = (AstStructType *) t;
     if (st->scope) scope_enter(st->scope);
-    
+
     bh_arr_each(AstStructMember *, smem, st->members) {
         if ((*smem)->initial_value != NULL) {
             SYMRES(expression, &(*smem)->initial_value);
-            
-            // CLEANUP: I hate that this is here. The type inference for a struct member should happen once the actual type is known.
-            // There seems to be a problem with setting it in the checker however, because whenever I disable this code, somehow
-            // the compiler gets to the code generation without all the types figured out???
-            // if ((*smem)->type_node == NULL && (*smem)->initial_value->type_node != NULL) {
-            //    (*smem)->type_node = (*smem)->initial_value->type_node;
-            // }
         }
     }
-    
+
     if (st->scope) scope_leave();
     return Symres_Success;
 }
index 3e44f60c835c4cde9b5d28668d08a3e06fac9c9e..5c35c5fdb4c122e76d14ef883382251a305c7ca9 100644 (file)
@@ -1273,7 +1273,7 @@ AstFunction* macro_resolve_header(AstMacro* macro, Arguments* args, OnyxToken* c
 
             char* err_msg=NULL;
             bh_arr(AstPolySolution) slns = find_polymorphic_slns(pp, PPLM_By_Arguments, args, &err_msg);
-            
+
             if (slns == NULL) {
                 if (flag_to_yield) {
                     flag_to_yield = 0;
@@ -1281,7 +1281,7 @@ AstFunction* macro_resolve_header(AstMacro* macro, Arguments* args, OnyxToken* c
                 }
 
                 if (callsite) onyx_report_error(callsite->pos, err_msg);
-                
+
                 return NULL;
             }
 
diff --git a/tests/bugs/macro_auto_return_not_resolved b/tests/bugs/macro_auto_return_not_resolved
new file mode 100644 (file)
index 0000000..27ba77d
--- /dev/null
@@ -0,0 +1 @@
+true
diff --git a/tests/bugs/macro_auto_return_not_resolved.onyx b/tests/bugs/macro_auto_return_not_resolved.onyx
new file mode 100644 (file)
index 0000000..573d9f9
--- /dev/null
@@ -0,0 +1,21 @@
+#load "core/std"
+
+use package core
+
+Point :: struct { x, y: i32; }
+
+#add_match hash.to_u32, macro (p: Point) -> #auto do return p.x * 1000 + p.y;
+
+#operator == macro (p1: Point, p2: Point) -> #auto {
+    return p1.x == p2.x && p1.y == p2.y;
+}
+
+main :: (args) => {
+    S := set.make(Point);
+
+    S << Point.{ 1, 2 };
+    S << Point.{ 2, 3 };
+    S << Point.{ 1, 2 };
+
+    set.has(^S, Point.{ 1, 2 }) |> println();
+}
\ No newline at end of file