fixed: cast error with new function semantics
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 20 Apr 2023 02:53:12 +0000 (21:53 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 20 Apr 2023 02:53:12 +0000 (21:53 -0500)
compiler/src/astnodes.c
compiler/src/wasm_emit.c
tests/aoc-2021/day12.onyx

index c68ad57486d078a6fbd46258b2a366e9125aece3..f604561219e0ec1fbfc9f6f2ea0aee8f9ed6cb4e 100644 (file)
@@ -1297,6 +1297,11 @@ b32 cast_is_legal(Type* from_, Type* to_, char** err_msg) {
         return 0;
     }
 
+    if (from->kind == Type_Kind_Function) {
+        *err_msg = "Can only cast a function to a 'u32'.";
+        return to == &basic_types[Basic_Kind_U32];
+    }
+
     if (   (type_is_simd(to) && !type_is_simd(from))
         || (!type_is_simd(to) && type_is_simd(from))) {
         *err_msg = "Can only perform a SIMD cast between SIMD types.";
index 5a5bc47d09989e0db95d38aba2cb516c877c9dee..1a1b0fcd03ccf5d110c93c46f84792d76da8f5df 100644 (file)
@@ -3777,6 +3777,12 @@ EMIT_FUNC(cast, AstUnaryOp* cast) {
         return;
     }
 
+    if (to->kind == Type_Kind_Basic && from->kind == Type_Kind_Function) {
+        WI(NULL, WI_DROP);
+        *pcode = code;
+        return;
+    }
+
     i32 fromidx = -1, toidx = -1;
     if (from->Basic.flags & Basic_Flag_Pointer || from->kind == Type_Kind_Array) {
         fromidx = 10;
index 34a54f0dc312cbcbcba56b7f5d1050e5f1f83f3d..c079d9bb3da740ae0d4514ce17207eeed9334393 100644 (file)
@@ -41,17 +41,14 @@ main :: (args) => {
         node_stack << .{ "start", 0, false };
 
         children_of :: (edges: &$T, name: str) -> Iterator(str) {
-            name_copy := new_temp(str);
-            *name_copy = name;
-
             return iter.concat(
                 iter.as_iter(edges)
-                |> iter.filter(name_copy, (x, n) => x.a == *n)
-                |> iter.map(x => x.b),
+                ->filter((x, |name: str|) => x.a == name)
+                ->map(x => x.b),
 
                 iter.as_iter(edges)
-                |> iter.filter(name_copy, (x, n) => x.b == *n)
-                |> iter.map(x => x.a)
+                ->filter((x, |name: str|) => x.b == name)
+                ->map(x => x.a)
             );
         }