From: Brendan Hansen Date: Thu, 20 Apr 2023 02:53:12 +0000 (-0500) Subject: fixed: cast error with new function semantics X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=8147854643a615a962a9e62505f6ab7876872f92;p=onyx.git fixed: cast error with new function semantics --- diff --git a/compiler/src/astnodes.c b/compiler/src/astnodes.c index c68ad574..f6045612 100644 --- a/compiler/src/astnodes.c +++ b/compiler/src/astnodes.c @@ -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."; diff --git a/compiler/src/wasm_emit.c b/compiler/src/wasm_emit.c index 5a5bc47d..1a1b0fcd 100644 --- a/compiler/src/wasm_emit.c +++ b/compiler/src/wasm_emit.c @@ -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; diff --git a/tests/aoc-2021/day12.onyx b/tests/aoc-2021/day12.onyx index 34a54f0d..c079d9bb 100644 --- a/tests/aoc-2021/day12.onyx +++ b/tests/aoc-2021/day12.onyx @@ -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) ); }