From a4fb3cfc4f1a8ed413a10f9dce928200da822b05 Mon Sep 17 00:00:00 2001 From: saqut Date: Fri, 19 Jun 2026 16:26:20 +0300 Subject: [PATCH] =?UTF-8?q?fix(tc):=20string=20s=C4=B1ralama=20operat?= =?UTF-8?q?=C3=B6rleri=20derleme=20zaman=C4=B1nda=20blokland=C4=B1=20(B5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sorun: TypeChecker < > <= >= için tip kontrolü yapmıyordu; string operandlarda VM sessizce intValue=0 karşılaştırıyordu. Düzeltme: karşılaştırma bloğu ikiye ayrıldı: == / != → string dahil herhangi tip (değişmedi) < > <= >= → isNumeric() kontrolü; string veya diğer sayısal-olmayan tipler E003 üretir, VM'e hiç ulaşmaz Aritmetik (+ - * / %) zaten sayısal-olmayan tipler için E003 üretiyordu; doğrulandı, değiştirilmedi. Altyapı: cmake/run_golden_error.cmake + CMakeLists.txt'e .compile_error desteği — derleme hatası bekleyen negatif golden testler için. Testler (19/19 yeşil): - string/ordering_error: string < → E003 (negatif test) - string/equality: string == / != çalışmaya devam ediyor (regresyon) Co-Authored-By: Claude Sonnet 4.6 --- CMakeLists.txt | 14 ++ build/.ninja_deps | Bin 82296 -> 83944 bytes build/.ninja_log | 11 +- build/CMakeFiles/VerifyGlobs.cmake | 2 + build/CTestTestfile.cmake | 4 + build/Testing/Temporary/CTestCostData.txt | 36 ++-- build/Testing/Temporary/LastTest.log | 174 ++++++++++-------- cmake/run_golden_error.cmake | 29 +++ src/semantic/type_checker.cpp | 25 ++- tests/golden/string/equality.expected | 4 + tests/golden/string/equality.sqt | 16 ++ .../string/ordering_error.compile_error | 1 + tests/golden/string/ordering_error.sqt | 10 + 13 files changed, 227 insertions(+), 99 deletions(-) create mode 100644 cmake/run_golden_error.cmake create mode 100644 tests/golden/string/equality.expected create mode 100644 tests/golden/string/equality.sqt create mode 100644 tests/golden/string/ordering_error.compile_error create mode 100644 tests/golden/string/ordering_error.sqt diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b48e77..285d5fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,4 +87,18 @@ foreach(SQT_FILE ${ALL_GOLDEN_SQT}) -P "${GOLDEN_SCRIPT}" ) endif() + + # Negatif test: .compile_error — derleme hatası beklenen golden testler. + # Dosya içeriği stderr'de aranır (regex/düz dize). + set(COMPILE_ERROR_EXPECTED "${CMAKE_SOURCE_DIR}/tests/golden/${BASE}.compile_error") + if(EXISTS "${COMPILE_ERROR_EXPECTED}") + add_test( + NAME "golden_${TNAME}_compile_error" + COMMAND ${CMAKE_COMMAND} + -DBINARY=${SAQUT_BINARY} + -DSOURCE=${SQT_FILE} + -DEXPECTED=${COMPILE_ERROR_EXPECTED} + -P "${CMAKE_SOURCE_DIR}/cmake/run_golden_error.cmake" + ) + endif() endforeach() diff --git a/build/.ninja_deps b/build/.ninja_deps index be2635324fa8709bd4451659a151b534f6da700e..8d0fe544caf2992478d8daf7b6244c182acaadef 100644 GIT binary patch delta 51 zcmey-#QLJ2wP6cmg(KeyR)&TZj0_BWnH$dd)@@$2ejh8}0tSYL1wb(_*Tc7c>!#bO HGfo2l{5KM& delta 11 ScmaFS&-$Z@wP6cmg(CnVwgl<` diff --git a/build/.ninja_log b/build/.ninja_log index c2fa57a..544b87b 100644 --- a/build/.ninja_log +++ b/build/.ninja_log @@ -11,14 +11,15 @@ 9 9708 1781873515651752771 CMakeFiles/saqut.dir/src/parser/nodes/binary_expr.cpp.o 5cc8b697133bcf64 9 7206 1781873515651861333 CMakeFiles/saqut.dir/src/parser/nodes/declarations.cpp.o c3d262615ede4c95 9 4452 1781874491015670524 CMakeFiles/saqut.dir/src/main.cpp.o 3cfef7a665d5bf87 -2704 2946 1781874878915205117 saqut f2e198803c4dbffb -0 22 1781874924882965311 build.ninja 1876a59d627a585 -0 22 1781874924882905555 /home/saqut/Masaüstü/saqutcompiler/build/cmake_install.cmake 1876a59d627a585 +2761 3022 1781875475188976192 saqut f2e198803c4dbffb +9 33 1781875559284118076 build.ninja 1876a59d627a585 +9 33 1781875559283948088 /home/saqut/Masaüstü/saqutcompiler/build/cmake_install.cmake 1876a59d627a585 8261 13474 1781873523902721486 CMakeFiles/saqut.dir/src/symbol/symbol_collector.cpp.o ec4e483b8ddb4007 5962 11851 1781873521603816495 CMakeFiles/saqut.dir/src/semantic/structural_validator.cpp.o 248faa3675024351 -7206 12730 1781873522847765087 CMakeFiles/saqut.dir/src/semantic/type_checker.cpp.o b29c133293d988b0 +8 2761 1781875472435265485 CMakeFiles/saqut.dir/src/semantic/type_checker.cpp.o b29c133293d988b0 9874 11363 1781873525515654821 CMakeFiles/saqut.dir/src/vm/interpreter.cpp.o b7dd80e002d68a1d 9 1858 1781873515651218159 CMakeFiles/saqut.dir/src/ir/ir_function.cpp.o 10f5e8dfd1461d69 9 1821 1781873515651428931 CMakeFiles/saqut.dir/src/ir/ir_program.cpp.o 9518231d970828da 9 2704 1781874876220317748 CMakeFiles/saqut.dir/src/ir/ir_generator.cpp.o 10a1ed4e1f52e530 -1 8 1781874876212318082 /home/saqut/Masaüstü/saqutcompiler/build/CMakeFiles/cmake.verify_globs 1813c41e0f312d7e +0 7 1781875472427263415 /home/saqut/Masaüstü/saqutcompiler/build/CMakeFiles/cmake.verify_globs 1813c41e0f312d7e +9 33 1781875559284118076 /home/saqut/Masaüstü/saqutcompiler/build/CTestTestfile.cmake 1876a59d627a585 diff --git a/build/CMakeFiles/VerifyGlobs.cmake b/build/CMakeFiles/VerifyGlobs.cmake index 341479f..85cb4c6 100644 --- a/build/CMakeFiles/VerifyGlobs.cmake +++ b/build/CMakeFiles/VerifyGlobs.cmake @@ -18,7 +18,9 @@ set(OLD_GLOB "/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/dce.sqt" "/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/folding.sqt" "/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/run_opt.sqt" + "/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/equality.sqt" "/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/hello.sqt" + "/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/ordering_error.sqt" ) if(NOT "${NEW_GLOB}" STREQUAL "${OLD_GLOB}") message("-- GLOB mismatch!") diff --git a/build/CTestTestfile.cmake b/build/CTestTestfile.cmake index 23d325b..3a0f124 100644 --- a/build/CTestTestfile.cmake +++ b/build/CTestTestfile.cmake @@ -36,5 +36,9 @@ add_test(golden_opt_run_opt "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/sa set_tests_properties(golden_opt_run_opt PROPERTIES _BACKTRACE_TRIPLES "/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;51;add_test;/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;0;") add_test(golden_opt_run_opt_run_opt "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/run_opt.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/run_opt.run_opt.expected" "-DOPTIMIZED=1" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake") set_tests_properties(golden_opt_run_opt_run_opt PROPERTIES _BACKTRACE_TRIPLES "/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;80;add_test;/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;0;") +add_test(golden_string_equality "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/equality.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/equality.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake") +set_tests_properties(golden_string_equality PROPERTIES _BACKTRACE_TRIPLES "/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;51;add_test;/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;0;") add_test(golden_string_hello "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/hello.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/hello.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake") set_tests_properties(golden_string_hello PROPERTIES _BACKTRACE_TRIPLES "/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;51;add_test;/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;0;") +add_test(golden_string_ordering_error_compile_error "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/ordering_error.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/ordering_error.compile_error" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden_error.cmake") +set_tests_properties(golden_string_ordering_error_compile_error PROPERTIES _BACKTRACE_TRIPLES "/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;95;add_test;/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;0;") diff --git a/build/Testing/Temporary/CTestCostData.txt b/build/Testing/Temporary/CTestCostData.txt index 7e972ad..a62c165 100644 --- a/build/Testing/Temporary/CTestCostData.txt +++ b/build/Testing/Temporary/CTestCostData.txt @@ -1,20 +1,22 @@ -unit_tests 13 0.352436 -golden_arithmetic_basic 13 0.000652347 -golden_fibonacci_fib 13 0.000724591 -golden_string_hello 13 0.00072588 -golden_arithmetic_precedence 12 0.000714208 -golden_loops_basic 12 0.000810632 -golden_loops_do_while_once 12 0.000818169 +unit_tests 14 0.305063 +golden_arithmetic_basic 14 0.000594672 +golden_fibonacci_fib 14 0.000625488 +golden_string_hello 14 0.000555013 +golden_arithmetic_precedence 13 0.000624411 +golden_loops_basic 13 0.000621234 +golden_loops_do_while_once 13 0.000607452 golden_opt_dce 2 0.00441751 golden_opt_folding 2 0.00456844 -golden_opt_dce_ir_opt 10 0.00095937 -golden_opt_folding_ir_opt 10 0.000934146 -golden_opt_run_opt 8 0.00122626 -golden_opt_run_opt_run_opt 8 0.00120176 -golden_logic_short_circuit 4 0.00248143 -golden_loops_do_while_truthy 3 0.00308889 -golden_loops_for_break_continue 2 0.00483077 -golden_loops_nested_break 2 0.0049106 -golden_loops_while_break_continue 2 0.00473685 -golden_logic_not_operator 1 0.00930197 +golden_opt_dce_ir_opt 11 0.000738665 +golden_opt_folding_ir_opt 11 0.000715714 +golden_opt_run_opt 9 0.000934623 +golden_opt_run_opt_run_opt 9 0.00092316 +golden_logic_short_circuit 5 0.00166261 +golden_loops_do_while_truthy 4 0.00202566 +golden_loops_for_break_continue 3 0.00282829 +golden_loops_nested_break 3 0.00274036 +golden_loops_while_break_continue 3 0.00275974 +golden_logic_not_operator 2 0.00406152 +golden_string_equality 1 0.0080422 +golden_string_ordering_error_compile_error 1 0.00786412 --- diff --git a/build/Testing/Temporary/LastTest.log b/build/Testing/Temporary/LastTest.log index 8e41c6d..e60a558 100644 --- a/build/Testing/Temporary/LastTest.log +++ b/build/Testing/Temporary/LastTest.log @@ -1,10 +1,10 @@ -Start testing: Jun 19 16:15 +03 +Start testing: Jun 19 16:25 +03 ---------------------------------------------------------- -1/17 Testing: unit_tests -1/17 Test: unit_tests +1/19 Testing: unit_tests +1/19 Test: unit_tests Command: "/usr/bin/bash" "/home/saqut/Masaüstü/saqutcompiler/tests/run.sh" Directory: /home/saqut/Masaüstü/saqutcompiler/build -"unit_tests" start time: Jun 19 16:15 +03 +"unit_tests" start time: Jun 19 16:25 +03 Output: ---------------------------------------------------------- === test_type === @@ -21,251 +21,281 @@ test.sqt:12:1: uyarı [W001]: y kullanılmıyor test_diagnostic: TUM TESTLER GECTI === TUM TESTLER GECTI === -Test time = 4.58 sec +Test time = 4.27 sec ---------------------------------------------------------- Test Passed. -"unit_tests" end time: Jun 19 16:15 +03 +"unit_tests" end time: Jun 19 16:26 +03 "unit_tests" time elapsed: 00:00:04 ---------------------------------------------------------- -2/17 Testing: golden_arithmetic_basic -2/17 Test: golden_arithmetic_basic +2/19 Testing: golden_arithmetic_basic +2/19 Test: golden_arithmetic_basic Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/arithmetic/basic.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/arithmetic/basic.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" Directory: /home/saqut/Masaüstü/saqutcompiler/build -"golden_arithmetic_basic" start time: Jun 19 16:15 +03 +"golden_arithmetic_basic" start time: Jun 19 16:26 +03 Output: ---------------------------------------------------------- Test time = 0.01 sec ---------------------------------------------------------- Test Passed. -"golden_arithmetic_basic" end time: Jun 19 16:15 +03 +"golden_arithmetic_basic" end time: Jun 19 16:26 +03 "golden_arithmetic_basic" time elapsed: 00:00:00 ---------------------------------------------------------- -3/17 Testing: golden_arithmetic_precedence -3/17 Test: golden_arithmetic_precedence +3/19 Testing: golden_arithmetic_precedence +3/19 Test: golden_arithmetic_precedence Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/arithmetic/precedence.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/arithmetic/precedence.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" Directory: /home/saqut/Masaüstü/saqutcompiler/build -"golden_arithmetic_precedence" start time: Jun 19 16:15 +03 +"golden_arithmetic_precedence" start time: Jun 19 16:26 +03 Output: ---------------------------------------------------------- Test time = 0.01 sec ---------------------------------------------------------- Test Passed. -"golden_arithmetic_precedence" end time: Jun 19 16:15 +03 +"golden_arithmetic_precedence" end time: Jun 19 16:26 +03 "golden_arithmetic_precedence" time elapsed: 00:00:00 ---------------------------------------------------------- -4/17 Testing: golden_fibonacci_fib -4/17 Test: golden_fibonacci_fib +4/19 Testing: golden_fibonacci_fib +4/19 Test: golden_fibonacci_fib Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/fibonacci/fib.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/fibonacci/fib.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" Directory: /home/saqut/Masaüstü/saqutcompiler/build -"golden_fibonacci_fib" start time: Jun 19 16:15 +03 +"golden_fibonacci_fib" start time: Jun 19 16:26 +03 Output: ---------------------------------------------------------- Test time = 0.01 sec ---------------------------------------------------------- Test Passed. -"golden_fibonacci_fib" end time: Jun 19 16:15 +03 +"golden_fibonacci_fib" end time: Jun 19 16:26 +03 "golden_fibonacci_fib" time elapsed: 00:00:00 ---------------------------------------------------------- -5/17 Testing: golden_logic_not_operator -5/17 Test: golden_logic_not_operator +5/19 Testing: golden_logic_not_operator +5/19 Test: golden_logic_not_operator Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/logic/not_operator.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/logic/not_operator.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" Directory: /home/saqut/Masaüstü/saqutcompiler/build -"golden_logic_not_operator" start time: Jun 19 16:15 +03 +"golden_logic_not_operator" start time: Jun 19 16:26 +03 Output: ---------------------------------------------------------- Test time = 0.01 sec ---------------------------------------------------------- Test Passed. -"golden_logic_not_operator" end time: Jun 19 16:15 +03 +"golden_logic_not_operator" end time: Jun 19 16:26 +03 "golden_logic_not_operator" time elapsed: 00:00:00 ---------------------------------------------------------- -6/17 Testing: golden_logic_short_circuit -6/17 Test: golden_logic_short_circuit +6/19 Testing: golden_logic_short_circuit +6/19 Test: golden_logic_short_circuit Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/logic/short_circuit.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/logic/short_circuit.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" Directory: /home/saqut/Masaüstü/saqutcompiler/build -"golden_logic_short_circuit" start time: Jun 19 16:15 +03 +"golden_logic_short_circuit" start time: Jun 19 16:26 +03 Output: ---------------------------------------------------------- Test time = 0.01 sec ---------------------------------------------------------- Test Passed. -"golden_logic_short_circuit" end time: Jun 19 16:15 +03 +"golden_logic_short_circuit" end time: Jun 19 16:26 +03 "golden_logic_short_circuit" time elapsed: 00:00:00 ---------------------------------------------------------- -7/17 Testing: golden_loops_basic -7/17 Test: golden_loops_basic +7/19 Testing: golden_loops_basic +7/19 Test: golden_loops_basic Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/basic.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/basic.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" Directory: /home/saqut/Masaüstü/saqutcompiler/build -"golden_loops_basic" start time: Jun 19 16:15 +03 +"golden_loops_basic" start time: Jun 19 16:26 +03 Output: ---------------------------------------------------------- Test time = 0.01 sec ---------------------------------------------------------- Test Passed. -"golden_loops_basic" end time: Jun 19 16:15 +03 +"golden_loops_basic" end time: Jun 19 16:26 +03 "golden_loops_basic" time elapsed: 00:00:00 ---------------------------------------------------------- -8/17 Testing: golden_loops_do_while_once -8/17 Test: golden_loops_do_while_once +8/19 Testing: golden_loops_do_while_once +8/19 Test: golden_loops_do_while_once Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/do_while_once.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/do_while_once.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" Directory: /home/saqut/Masaüstü/saqutcompiler/build -"golden_loops_do_while_once" start time: Jun 19 16:15 +03 +"golden_loops_do_while_once" start time: Jun 19 16:26 +03 Output: ---------------------------------------------------------- Test time = 0.01 sec ---------------------------------------------------------- Test Passed. -"golden_loops_do_while_once" end time: Jun 19 16:15 +03 +"golden_loops_do_while_once" end time: Jun 19 16:26 +03 "golden_loops_do_while_once" time elapsed: 00:00:00 ---------------------------------------------------------- -9/17 Testing: golden_loops_do_while_truthy -9/17 Test: golden_loops_do_while_truthy +9/19 Testing: golden_loops_do_while_truthy +9/19 Test: golden_loops_do_while_truthy Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/do_while_truthy.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/do_while_truthy.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" Directory: /home/saqut/Masaüstü/saqutcompiler/build -"golden_loops_do_while_truthy" start time: Jun 19 16:15 +03 +"golden_loops_do_while_truthy" start time: Jun 19 16:26 +03 Output: ---------------------------------------------------------- Test time = 0.01 sec ---------------------------------------------------------- Test Passed. -"golden_loops_do_while_truthy" end time: Jun 19 16:15 +03 +"golden_loops_do_while_truthy" end time: Jun 19 16:26 +03 "golden_loops_do_while_truthy" time elapsed: 00:00:00 ---------------------------------------------------------- -10/17 Testing: golden_loops_for_break_continue -10/17 Test: golden_loops_for_break_continue +10/19 Testing: golden_loops_for_break_continue +10/19 Test: golden_loops_for_break_continue Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/for_break_continue.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/for_break_continue.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" Directory: /home/saqut/Masaüstü/saqutcompiler/build -"golden_loops_for_break_continue" start time: Jun 19 16:15 +03 +"golden_loops_for_break_continue" start time: Jun 19 16:26 +03 Output: ---------------------------------------------------------- Test time = 0.01 sec ---------------------------------------------------------- Test Passed. -"golden_loops_for_break_continue" end time: Jun 19 16:15 +03 +"golden_loops_for_break_continue" end time: Jun 19 16:26 +03 "golden_loops_for_break_continue" time elapsed: 00:00:00 ---------------------------------------------------------- -11/17 Testing: golden_loops_nested_break -11/17 Test: golden_loops_nested_break +11/19 Testing: golden_loops_nested_break +11/19 Test: golden_loops_nested_break Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/nested_break.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/nested_break.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" Directory: /home/saqut/Masaüstü/saqutcompiler/build -"golden_loops_nested_break" start time: Jun 19 16:15 +03 +"golden_loops_nested_break" start time: Jun 19 16:26 +03 Output: ---------------------------------------------------------- Test time = 0.01 sec ---------------------------------------------------------- Test Passed. -"golden_loops_nested_break" end time: Jun 19 16:15 +03 +"golden_loops_nested_break" end time: Jun 19 16:26 +03 "golden_loops_nested_break" time elapsed: 00:00:00 ---------------------------------------------------------- -12/17 Testing: golden_loops_while_break_continue -12/17 Test: golden_loops_while_break_continue +12/19 Testing: golden_loops_while_break_continue +12/19 Test: golden_loops_while_break_continue Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/while_break_continue.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/while_break_continue.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" Directory: /home/saqut/Masaüstü/saqutcompiler/build -"golden_loops_while_break_continue" start time: Jun 19 16:15 +03 +"golden_loops_while_break_continue" start time: Jun 19 16:26 +03 Output: ---------------------------------------------------------- Test time = 0.01 sec ---------------------------------------------------------- Test Passed. -"golden_loops_while_break_continue" end time: Jun 19 16:15 +03 +"golden_loops_while_break_continue" end time: Jun 19 16:26 +03 "golden_loops_while_break_continue" time elapsed: 00:00:00 ---------------------------------------------------------- -13/17 Testing: golden_opt_dce_ir_opt -13/17 Test: golden_opt_dce_ir_opt +13/19 Testing: golden_opt_dce_ir_opt +13/19 Test: golden_opt_dce_ir_opt Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/dce.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/dce.ir_opt.expected" "-DCOMMAND=ir" "-DOPTIMIZED=1" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" Directory: /home/saqut/Masaüstü/saqutcompiler/build -"golden_opt_dce_ir_opt" start time: Jun 19 16:15 +03 +"golden_opt_dce_ir_opt" start time: Jun 19 16:26 +03 Output: ---------------------------------------------------------- Test time = 0.01 sec ---------------------------------------------------------- Test Passed. -"golden_opt_dce_ir_opt" end time: Jun 19 16:15 +03 +"golden_opt_dce_ir_opt" end time: Jun 19 16:26 +03 "golden_opt_dce_ir_opt" time elapsed: 00:00:00 ---------------------------------------------------------- -14/17 Testing: golden_opt_folding_ir_opt -14/17 Test: golden_opt_folding_ir_opt +14/19 Testing: golden_opt_folding_ir_opt +14/19 Test: golden_opt_folding_ir_opt Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/folding.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/folding.ir_opt.expected" "-DCOMMAND=ir" "-DOPTIMIZED=1" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" Directory: /home/saqut/Masaüstü/saqutcompiler/build -"golden_opt_folding_ir_opt" start time: Jun 19 16:15 +03 +"golden_opt_folding_ir_opt" start time: Jun 19 16:26 +03 Output: ---------------------------------------------------------- Test time = 0.01 sec ---------------------------------------------------------- Test Passed. -"golden_opt_folding_ir_opt" end time: Jun 19 16:15 +03 +"golden_opt_folding_ir_opt" end time: Jun 19 16:26 +03 "golden_opt_folding_ir_opt" time elapsed: 00:00:00 ---------------------------------------------------------- -15/17 Testing: golden_opt_run_opt -15/17 Test: golden_opt_run_opt +15/19 Testing: golden_opt_run_opt +15/19 Test: golden_opt_run_opt Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/run_opt.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/run_opt.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" Directory: /home/saqut/Masaüstü/saqutcompiler/build -"golden_opt_run_opt" start time: Jun 19 16:15 +03 +"golden_opt_run_opt" start time: Jun 19 16:26 +03 Output: ---------------------------------------------------------- Test time = 0.01 sec ---------------------------------------------------------- Test Passed. -"golden_opt_run_opt" end time: Jun 19 16:15 +03 +"golden_opt_run_opt" end time: Jun 19 16:26 +03 "golden_opt_run_opt" time elapsed: 00:00:00 ---------------------------------------------------------- -16/17 Testing: golden_opt_run_opt_run_opt -16/17 Test: golden_opt_run_opt_run_opt +16/19 Testing: golden_opt_run_opt_run_opt +16/19 Test: golden_opt_run_opt_run_opt Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/run_opt.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/run_opt.run_opt.expected" "-DOPTIMIZED=1" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" Directory: /home/saqut/Masaüstü/saqutcompiler/build -"golden_opt_run_opt_run_opt" start time: Jun 19 16:15 +03 +"golden_opt_run_opt_run_opt" start time: Jun 19 16:26 +03 Output: ---------------------------------------------------------- Test time = 0.01 sec ---------------------------------------------------------- Test Passed. -"golden_opt_run_opt_run_opt" end time: Jun 19 16:15 +03 +"golden_opt_run_opt_run_opt" end time: Jun 19 16:26 +03 "golden_opt_run_opt_run_opt" time elapsed: 00:00:00 ---------------------------------------------------------- -17/17 Testing: golden_string_hello -17/17 Test: golden_string_hello -Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/hello.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/hello.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" +17/19 Testing: golden_string_equality +17/19 Test: golden_string_equality +Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/equality.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/equality.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" Directory: /home/saqut/Masaüstü/saqutcompiler/build -"golden_string_hello" start time: Jun 19 16:15 +03 +"golden_string_equality" start time: Jun 19 16:26 +03 Output: ---------------------------------------------------------- Test time = 0.01 sec ---------------------------------------------------------- Test Passed. -"golden_string_hello" end time: Jun 19 16:15 +03 +"golden_string_equality" end time: Jun 19 16:26 +03 +"golden_string_equality" time elapsed: 00:00:00 +---------------------------------------------------------- + +18/19 Testing: golden_string_hello +18/19 Test: golden_string_hello +Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/hello.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/hello.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" +Directory: /home/saqut/Masaüstü/saqutcompiler/build +"golden_string_hello" start time: Jun 19 16:26 +03 +Output: +---------------------------------------------------------- + +Test time = 0.01 sec +---------------------------------------------------------- +Test Passed. +"golden_string_hello" end time: Jun 19 16:26 +03 "golden_string_hello" time elapsed: 00:00:00 ---------------------------------------------------------- -End testing: Jun 19 16:15 +03 +19/19 Testing: golden_string_ordering_error_compile_error +19/19 Test: golden_string_ordering_error_compile_error +Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/ordering_error.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/ordering_error.compile_error" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden_error.cmake" +Directory: /home/saqut/Masaüstü/saqutcompiler/build +"golden_string_ordering_error_compile_error" start time: Jun 19 16:26 +03 +Output: +---------------------------------------------------------- + +Test time = 0.01 sec +---------------------------------------------------------- +Test Passed. +"golden_string_ordering_error_compile_error" end time: Jun 19 16:26 +03 +"golden_string_ordering_error_compile_error" time elapsed: 00:00:00 +---------------------------------------------------------- + +End testing: Jun 19 16:26 +03 diff --git a/cmake/run_golden_error.cmake b/cmake/run_golden_error.cmake new file mode 100644 index 0000000..9ee0c04 --- /dev/null +++ b/cmake/run_golden_error.cmake @@ -0,0 +1,29 @@ +# run_golden_error.cmake — derleme hatası BEKLEYEN golden test. +# +# Parametreler (cmake -D ile geçilir): +# BINARY — saqut binary yolu +# SOURCE — test .sqt dosyası (tam yol) +# EXPECTED — beklenen hata içeriği (.compile_error dosyası); stderr bu +# metni içermeli (regex veya düz dize olarak eşleşir) + +execute_process( + COMMAND "${BINARY}" run "file:${SOURCE}" + OUTPUT_VARIABLE STDOUT_OUT + ERROR_VARIABLE STDERR_OUT + RESULT_VARIABLE EXIT_CODE +) + +if(EXIT_CODE EQUAL 0) + message(FATAL_ERROR + "Derleme hatası bekleniyordu ama program başarıyla çalıştı: ${SOURCE}\n" + "Çıktı: ${STDOUT_OUT}") +endif() + +file(READ "${EXPECTED}" EXPECTED_CONTENT) +string(STRIP "${EXPECTED_CONTENT}" EXPECTED_CONTENT) + +if(NOT STDERR_OUT MATCHES "${EXPECTED_CONTENT}") + message(FATAL_ERROR + "Beklenen '${EXPECTED_CONTENT}' mesajı stderr'de bulunamadı: ${SOURCE}\n" + "Stderr: ${STDERR_OUT}") +endif() diff --git a/src/semantic/type_checker.cpp b/src/semantic/type_checker.cpp index f037b53..3e75649 100644 --- a/src/semantic/type_checker.cpp +++ b/src/semantic/type_checker.cpp @@ -274,14 +274,29 @@ Type TypeChecker::checkExpr(ASTNode* node, const Type& expected) { break; } - // Karşılaştırma - if (bin->Operator == TokenType::EQUAL_EQUAL || - bin->Operator == TokenType::BANG_EQUAL || - bin->Operator == TokenType::LESS || + // Eşitlik karşılaştırması: string dahil herhangi tiple çalışır + if (bin->Operator == TokenType::EQUAL_EQUAL || + bin->Operator == TokenType::BANG_EQUAL) { + result = Type::Bool(); + break; + } + + // Sıralama karşılaştırması: YALNIZCA sayısal tipler + if (bin->Operator == TokenType::LESS || bin->Operator == TokenType::LESS_EQUAL || bin->Operator == TokenType::GREATER || bin->Operator == TokenType::GREATER_EQUAL) { - result = Type::Bool(); + if (leftType.isError() || rightType.isError()) { + result = Type::error(); // önceki hata, sessiz geç + } else if (leftType.isNumeric() && rightType.isNumeric()) { + result = Type::Bool(); + } else { + diag_.report("E003", bin->loc, + "Sıralama operatörü yalnızca sayısal tiplerle kullanılabilir: " + + leftType.toString() + + " — string için yalnızca == ve != kullanın"); + result = Type::error(); + } break; } diff --git a/tests/golden/string/equality.expected b/tests/golden/string/equality.expected new file mode 100644 index 0000000..d80fc78 --- /dev/null +++ b/tests/golden/string/equality.expected @@ -0,0 +1,4 @@ +1 +0 +1 +0 diff --git a/tests/golden/string/equality.sqt b/tests/golden/string/equality.sqt new file mode 100644 index 0000000..872ddb5 --- /dev/null +++ b/tests/golden/string/equality.sqt @@ -0,0 +1,16 @@ +// Regresyon testi: string == ve != çalışmaya devam etmeli. +// TypeChecker string sıralama operatörlerini bloklamasına rağmen +// eşitlik operatörleri string ile kullanılabilmeli. + +int main() { + string a = "merhaba"; + string b = "merhaba"; + string c = "dunya"; + + print(a == b); + print(a == c); + print(a != c); + print(b != b); + + return 0; +} diff --git a/tests/golden/string/ordering_error.compile_error b/tests/golden/string/ordering_error.compile_error new file mode 100644 index 0000000..e8b2dab --- /dev/null +++ b/tests/golden/string/ordering_error.compile_error @@ -0,0 +1 @@ +E003 diff --git a/tests/golden/string/ordering_error.sqt b/tests/golden/string/ordering_error.sqt new file mode 100644 index 0000000..0750cb7 --- /dev/null +++ b/tests/golden/string/ordering_error.sqt @@ -0,0 +1,10 @@ +// Negatif test: string sıralama operatörleri derleme hatası vermeli. +// Bu dosya DERLENMEMELI — TypeChecker E003 üretmeli. +// < > <= >= operatörlerinin her biri string ile bloklanır. + +int main() { + string a = "merhaba"; + string b = "dunya"; + if (a < b) { return 1; } + return 0; +}