From: Brendan Hansen Date: Sat, 4 Dec 2021 21:10:26 +0000 (-0600) Subject: added error when using 'any' in macros (temporary fix) X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=c876ec54f206786a0697318ece0fd5fa2fe1746d;p=onyx.git added error when using 'any' in macros (temporary fix) --- diff --git a/src/utils.c b/src/utils.c index 1be2a5be..18f1569f 100644 --- a/src/utils.c +++ b/src/utils.c @@ -510,10 +510,16 @@ void expand_macro(AstCall** pcall, AstFunction* template) { // HACK HACK HACK This is probably very wrong. I don't know what guarentees that // the paramters and arguments are going to be in the same order exactly. - // Type *any_type = type_build_from_ast(context.ast_alloc, builtin_any_type); + Type *any_type = type_build_from_ast(context.ast_alloc, builtin_any_type); fori (i, 0, bh_arr_length(call->args.values)) { AstNode *value = (AstNode *) ((AstArgument *) call->args.values[i])->value; - // assert(template->params[i].local->type); + assert(template->params[i].local->type); + + Type *param_type = template->params[i].local->type; + if (param_type == any_type + || (param_type->kind == Type_Kind_VarArgs && param_type->VarArgs.elem == any_type)) { + onyx_report_error(macro->token->pos, "Currently, macros do not support arguments of type 'any' or '..any'."); + } symbol_introduce(argument_scope, template->params[i].local->token, value); } diff --git a/tests/aoc-2021/day01.onyx b/tests/aoc-2021/day01.onyx index 8664c136..8a67a4c8 100644 --- a/tests/aoc-2021/day01.onyx +++ b/tests/aoc-2021/day01.onyx @@ -19,7 +19,7 @@ main :: (args) => { reader := io.reader_make(^file); defer os.close(^file); - nums := array.make(i32); + nums: [..] i32; while !io.reader_empty(^reader) { nums << io.read_u32(^reader); io.skip_whitespace(^reader); @@ -31,7 +31,7 @@ main :: (args) => { } { // Part 2 - windows := array.make(i32); + windows: [..] i32; for i: range.{ 0, nums.count - 2 } { sum := 0; for k: i .. i+3 do sum += nums[k]; diff --git a/tests/aoc-2021/day03.onyx b/tests/aoc-2021/day03.onyx index fe2b70ba..bf743ccd 100644 --- a/tests/aoc-2021/day03.onyx +++ b/tests/aoc-2021/day03.onyx @@ -29,7 +29,7 @@ main :: (args) => { for os.with_file("./tests/aoc-2021/input/day03.txt") { reader := io.reader_make(it); - nums := array.make(i32); + nums: [..] i32; while !io.reader_empty(^reader) { nums << read_binary(^reader); } diff --git a/tests/interfaces.onyx b/tests/interfaces.onyx index 586e7c66..f113a483 100644 --- a/tests/interfaces.onyx +++ b/tests/interfaces.onyx @@ -29,8 +29,8 @@ cast_able :: #match { } cast_able_to_int :: #match { - macro (_: $T) -> bool where CanCastTo(T, i32) { return true; }, - macro (_: any) -> bool { return false; }, + macro (_: $T) -> bool where CanCastTo(T, i32) { return true; }, + macro (_: $T) -> bool { return false; }, } do_math :: macro (x, y: $T) -> T where SemiRing(T) {