From f6801e3eeb5649ea86a04e13ac82866203fd4b50 Mon Sep 17 00:00:00 2001 From: Niels Bross Date: Sun, 24 Aug 2025 11:37:16 +0200 Subject: [PATCH] Fix type result on binary compuations. --- Semantic_Analysis.jai | 18 +++++++++++-- Test.jai | 44 +++++++++++++++---------------- test/semant/wrong_multiply.golden | 28 ++++++++++++++++++-- 3 files changed, 64 insertions(+), 26 deletions(-) diff --git a/Semantic_Analysis.jai b/Semantic_Analysis.jai index 1bca38c..1dbae4f 100644 --- a/Semantic_Analysis.jai +++ b/Semantic_Analysis.jai @@ -1435,9 +1435,13 @@ check_node :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_H variable, handle := new_type_variable(checker); lhs_type := from_handle(checker, lhs_var); - variable.type = lhs_type.type; + rhs_type := from_handle(checker, rhs_var); + + + + variable.type = lhs_type.type; variable.typename = lhs_type.typename; - variable.scope = lhs_type.scope; + variable.scope = lhs_type.scope; variable.source_node = node; node.type_variable = handle; add_child(variable, lhs_var); @@ -1452,6 +1456,16 @@ check_node :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_H type_mismatch(checker, node, node.children[1], lhs_var, rhs_var); return 0; } + + if lhs_type.type == .Struct { + variable.type = lhs_type.type; + variable.typename = lhs_type.typename; + variable.scope = lhs_type.scope; + } else if rhs_type.type == .Struct { + variable.type = rhs_type.type; + variable.typename = rhs_type.typename; + variable.scope = rhs_type.scope; + } } case .TOKEN_ASSIGN; { if !types_compatible(checker, lhs_var, rhs_var) { diff --git a/Test.jai b/Test.jai index 9ab86e4..9dfb0d7 100644 --- a/Test.jai +++ b/Test.jai @@ -372,8 +372,8 @@ run_test_new :: (file_path : string, stage_flags : Stage_Flags, results : *[..]R } } -run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_Type = 0) { - print("%Running test: %......", cyan(), test_case.path); +run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_Type = 0, builder : *String_Builder) { + print_to_builder(builder, "%Running test: %......", cyan(), test_case.path); // path 30 // len 35 @@ -387,7 +387,7 @@ run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_ len := 50; rest := len - test_case.path.count; for i: 0..rest { - print(" "); + append(builder, " "); } run_test_new(test_case.path, test_case.stage_flags, results, output_type); @@ -416,7 +416,7 @@ run_test_suite :: (using suite : *Test_Suite, output_type : Output_Type = 0) { init_string_builder(*builder,, temp); for test_case : test_cases { - run_test(test_case, *suite.results, output_type); + run_test(test_case, *suite.results, output_type, *builder); for < suite.results { result := suite.results[it_index]; @@ -432,7 +432,7 @@ run_test_suite :: (using suite : *Test_Suite, output_type : Output_Type = 0) { array_add(*failed_test_paths, .{ result.path, tprint("golden file not found for %", stage_to_string(result.stage)) }); } } - evaluate_result(result); + evaluate_result(result, *builder); } else { break; } @@ -440,7 +440,7 @@ run_test_suite :: (using suite : *Test_Suite, output_type : Output_Type = 0) { // print("\n"); } - print("\n"); + append(*builder, "\n"); if output_type == 0 { if failed_test_paths.count == 0 { @@ -530,42 +530,42 @@ stage_to_string :: (stage : Stage_Flags) -> string { } } -evaluate_result :: (result : Result) { +evaluate_result :: (result : Result, builder : *String_Builder) { stage : string = stage_to_string(result.stage); if #complete result.type == { case .File_Read_Failed; { - print(" %", red()); - print("failed with File_Read_Failed\n"); + print_to_builder(builder, " %", red()); + print_to_builder(builder, "failed with File_Read_Failed\n"); } case .Golden_File_Not_Found; { - print(" %", red()); - print("failed with Golden File Not Found for stage %\n", stage); + print_to_builder(builder, " %", red()); + print_to_builder(builder, "failed with Golden File Not Found for stage %\n", stage); } case .StdOut; { } case .Golden_Output; { - print(" %", yellow()); - print("output new golden file at %\n", result.golden_path); + print_to_builder(builder, " %", yellow()); + print_to_builder(builder, "output new golden file at %\n", result.golden_path); } case .Passed; { - print(" %", green()); - print("passed %\n", stage); + print_to_builder(builder, " %", green()); + print_to_builder(builder, "passed %\n", stage); } case .Failed; { - print(" %", red()); - print("failed %\n", stage); + print_to_builder(builder, " %", red()); + print_to_builder(builder, "failed %\n", stage); } } if result.info_text.count > 0 { - print("%", cyan()); - print("--- Info text ---\n"); - print("%", yellow()); - print("%\n", result.info_text); + print_to_builder(builder, "%", cyan()); + print_to_builder(builder, "--- Info text ---\n"); + print_to_builder(builder, "%", yellow()); + print_to_builder(builder, "%\n", result.info_text); } - print("%", reset_color()); + print_to_builder(builder, "%", reset_color()); } main :: () { diff --git a/test/semant/wrong_multiply.golden b/test/semant/wrong_multiply.golden index c92670d..506863e 100644 --- a/test/semant/wrong_multiply.golden +++ b/test/semant/wrong_multiply.golden @@ -1,4 +1,28 @@ -test/wrong_multiply.ink:4,34: error: Type mismatch. Expected float got float2 +test/wrong_multiply.ink:4,18: error: Procedure call did not match any of the possible overloads for 'float4' + found: + result : float4 = float4(1.0, foo * res, 0.0, 1.0); + ^^^^^^ + + While matching argument 2 in function call. + result : float4 = float4(1.0, foo * res, 0.0, 1.0); + ^ + Possible overloads: + foreign float4 :: (float, float, float, float) -> float4; (test/wrong_multiply.ink:86) + foreign float4 :: (float4) -> float4; (test/wrong_multiply.ink:87) + foreign float4 :: (float2, float2) -> float4; (test/wrong_multiply.ink:88) + foreign float4 :: (float2, float, float) -> float4; (test/wrong_multiply.ink:89) + foreign float4 :: (float, float2, float) -> float4; (test/wrong_multiply.ink:90) + foreign float4 :: (float, float2, float) -> float4; (test/wrong_multiply.ink:90) + foreign float4 :: (float, float, float2) -> float4; (test/wrong_multiply.ink:91) + foreign float4 :: (float, float, float2) -> float4; (test/wrong_multiply.ink:91) + foreign float4 :: (float3, float) -> float4; (test/wrong_multiply.ink:92) + foreign float4 :: (float3, float) -> float4; (test/wrong_multiply.ink:92) + foreign float4 :: (float, float3) -> float4; (test/wrong_multiply.ink:93) + foreign float4 :: (float, float3) -> float4; (test/wrong_multiply.ink:93) + foreign float4 :: (float) -> float4; (test/wrong_multiply.ink:94) + foreign float4 :: (float) -> float4; (test/wrong_multiply.ink:94) + +test/wrong_multiply.ink:4,34: error: Type mismatch. Expected float got float2  found: result : float4 = float4(1.0, foo * res, 0.0, 1.0); ^ @@ -6,6 +30,6 @@ float got: - res : float2 = float2(2.0, 2.0) + result : float4 = float4(1.0, foo * res, 0.0, 1.0);  \ No newline at end of file