added error when using 'any' in macros (temporary fix)
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 4 Dec 2021 21:10:26 +0000 (15:10 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 4 Dec 2021 21:10:26 +0000 (15:10 -0600)
src/utils.c
tests/aoc-2021/day01.onyx
tests/aoc-2021/day03.onyx
tests/interfaces.onyx

index 1be2a5be5a40de3c50ff8fe85cce703c73416995..18f1569f24056af14bb3d976218fb4e841d22cbd 100644 (file)
@@ -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);
     }
index 8664c136e4dca5fe5f39f799151bbe77808e72f9..8a67a4c8881574f690ed87d593d2cc4658f206f6 100644 (file)
@@ -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];
index fe2b70bad1285f4034270ea493f4e88fc0575770..bf743ccd4f6c1e0ff3b81e6a8e00c4136073f22f 100644 (file)
@@ -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);
         }
index 586e7c664634ecce878be5a6fed4748bd4fc5f9e..f113a483898412dde3237203762e126372ac6f50 100644 (file)
@@ -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) {