From: Brendan Hansen Date: Sun, 29 Aug 2021 04:05:07 +0000 (-0500) Subject: bugfix with macros with auto-return type X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=307e73ac1a48891994c05ee50ea1010947797d3e;p=onyx.git bugfix with macros with auto-return type --- diff --git a/bin/onyx b/bin/onyx index 30b2a890..3fa5c373 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/docs/bugs b/docs/bugs index c7739086..e3ead457 100644 --- 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. diff --git a/src/onyxchecker.c b/src/onyxchecker.c index ce564b16..d581a2dc 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -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; } diff --git a/src/onyxsymres.c b/src/onyxsymres.c index 0bc9b32a..01d86ee5 100644 --- a/src/onyxsymres.c +++ b/src/onyxsymres.c @@ -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; } diff --git a/src/onyxutils.c b/src/onyxutils.c index 3e44f60c..5c35c5fd 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -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 index 00000000..27ba77dd --- /dev/null +++ b/tests/bugs/macro_auto_return_not_resolved @@ -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 index 00000000..573d9f91 --- /dev/null +++ b/tests/bugs/macro_auto_return_not_resolved.onyx @@ -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