From 67b966cb5b75e545df9321d7954ed40135356bc0 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Wed, 29 Mar 2023 08:03:43 +0200 Subject: [PATCH] Fixed bad error message when no return value + compound inferred type --- core_main.cpp | 1 - core_typechecking.cpp | 2 +- examples/push_struct.core | 20 ++++++++++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core_main.cpp b/core_main.cpp index a770430..cb0623c 100644 --- a/core_main.cpp +++ b/core_main.cpp @@ -50,7 +50,6 @@ Future features - [ ] Way to import and force evaluate #import_lazy #import ? Redesign: -- [ ] Redesign Type map to use List and reduce wasting space - [ ] Casting syntax In the future diff --git a/core_typechecking.cpp b/core_typechecking.cpp index e09b4a9..79c9bfa 100644 --- a/core_typechecking.cpp +++ b/core_typechecking.cpp @@ -1466,7 +1466,7 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str } if (!type) type = compound_and_const_string_context; - if (!type) + if (type == pctx->type_void || type == nullptr) compiler_error(node->pos, "Couldn't infer type of compound expression"); type_complete(type); diff --git a/examples/push_struct.core b/examples/push_struct.core index a91df95..9c1b407 100644 --- a/examples/push_struct.core +++ b/examples/push_struct.core @@ -1,15 +1,23 @@ -#import "Arena.core" +MA :: #import "Arena.core" -// @todo: -// Add new special type #Type_Size +/* +PushStruct :: (a: *MA.Arena, $Type): *Type + size := size_of(Type) + result := PushSize(a, size) + return result +*/ -PushStruct :: (a: *Arena, type: Type /*#Type_Size*/): *void +Color :: struct ;; r: F32; g: F32; b: F32; a: F32 +AlmostLinearToSRGB :: (a: Color): Color;; return {asd(a.r), asd(a.g), asd(a.b), a.a} + +PushStruct :: (a: *MA.Arena, type: Type): *void ti := GetTypeInfo(type) - result := PushSize(a, ti.size->Base.SizeU) + result := MA.PushSize(a, ti.size->U64) return result main :: (argc: int, argv: **char): int - arena: Arena + arena: MA.Arena a: *int = PushStruct(&arena, int) + Assert(arena.len == SizeOf(int)) return 0 \ No newline at end of file