From 3207a390c89a98088b6ac1351465a453fb13d10c Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Fri, 21 Apr 2023 08:39:33 +0200 Subject: [PATCH] Core: Fix couldnt infer compound expression --- build/rtsgame/main.core | 18 +++++++----------- core_typechecking.cpp | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/build/rtsgame/main.core b/build/rtsgame/main.core index c016f83..9af3fd4 100644 --- a/build/rtsgame/main.core +++ b/build/rtsgame/main.core @@ -66,10 +66,6 @@ Add(&guys, {100, 100}) // Error! Couldn't infer type of compound expression // if Mode == 1 && colliding && IsMouseButtonPressed(MOUSE_BUTTON_LEFT) ;; MAP.CurrentMAP.actors.data[0].p = {x,y} -// @compiler_todo: It's possible to have 2 definitions with same name. 1 global, 1 local -// Mode := 0 -// main :: () -// if IsKeyPressed(KEY_F1) ;; Mode := 0 #import "raylib.core" #load "array.core" @@ -102,6 +98,7 @@ MouseSelectionPivot: Vector2 MouseSelectionBox: Rectangle MouseSelectedActors: Array(*MAP.Actor) // @todo: ids + main :: (): int MAP.Init() @@ -129,7 +126,6 @@ main :: (): int target_color.a = 255/2 for !WindowShouldClose() - WinX = GetScreenWidth() WinY = GetScreenHeight() MouseX = GetMouseX() @@ -143,7 +139,7 @@ main :: (): int MouseSelecting = true if IsMouseButtonPressed(MOUSE_BUTTON_LEFT) MouseSelectionPivot = MouseP - MouseSelectionBox = Rectangle{ + MouseSelectionBox = { MouseSelectionPivot.x, MouseSelectionPivot.y, MouseP.x - MouseSelectionPivot.x, @@ -176,14 +172,14 @@ main :: (): int BeginDrawing() ClearBackground(RAYWHITE) - map_rectangle: Rectangle = {0, 0, map.x->F32 * RectX, map.y->F32 * RectY} + map_rectangle := Rectangle{0, 0, map.x->F32 * RectX, map.y->F32 * RectY} DrawRectangleRec(map_rectangle, LIGHTGRAY) for x := 0, x < map.x, x += 1 for y := 0, y < map.y, y += 1 it := map.data + (x + y*map.x) - r: Rectangle = {x->F32 * RectX, y->F32 * RectY, RectX, RectY} - r2: Rectangle = {r.x + 1, r.y + 1, r.width - 2, r.height - 2} + r := Rectangle{x->F32 * RectX, y->F32 * RectY, RectX, RectY} + r2 := Rectangle{r.x + 1, r.y + 1, r.width - 2, r.height - 2} colliding := CheckCollisionPointRec(MouseP, r) color := RAYWHITE @@ -195,7 +191,7 @@ main :: (): int Add(&ANI_SetTiles, {true, {x,y}}) if colliding && IsMouseButtonDown(MOUSE_BUTTON_RIGHT) Add(&ANI_SetTiles, {false, {x,y}}) - if colliding == true ;; color = Color{a = 100} + if colliding == true ;; color = {a = 100} DrawRectangleRec(r2, color) @@ -217,7 +213,7 @@ main :: (): int wd := w - wt hd := h - ht - r: Rectangle = {x + wd/2, y + hd/2, wt, ht} + r := Rectangle{x + wd/2, y + hd/2, wt, ht} DrawRectangleRec(r, GRAY) diff --git a/core_typechecking.cpp b/core_typechecking.cpp index ae39f0d..2c28527 100644 --- a/core_typechecking.cpp +++ b/core_typechecking.cpp @@ -1285,7 +1285,7 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str assert(is_flag_set(node->flags, AST_STMT)); Operand left = resolve_expr(node->left, AST_CANT_BE_NULL, 0, field_access_scope); if (!left.is_lvalue) compiler_error(node->pos, "Assigning to rvalue"); - Operand right = resolve_expr(node->right, AST_CANT_BE_NULL, 0, field_access_scope); + Operand right = resolve_expr(node->right, AST_CANT_BE_NULL, left.type, field_access_scope); // @warning: Could be buggy, previously we strictly matched if types are exact // need to test this with slices and stuff