diff --git a/releasenotes.md b/releasenotes.md index 8fe68282b..411073ed8 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -78,6 +78,7 @@ - Incorrect zero analysis on `foo["test"] = {}` #1360. - Bug converting untyped list #1360. - Benchmark / test no longer suppresses debug info. #1364. +- Bug when compile time subtracting a distinct type. ### Stdlib changes diff --git a/src/compiler/llvm_codegen.c b/src/compiler/llvm_codegen.c index 1208322f8..ab38aee6a 100644 --- a/src/compiler/llvm_codegen.c +++ b/src/compiler/llvm_codegen.c @@ -1303,6 +1303,9 @@ INLINE GenContext *llvm_gen_tests(Module** modules, unsigned module_count, LLVMC Path *test_path = path_create_from_string("_$test", 5, INVALID_SPAN); Module *test_module = compiler_find_or_create_module(test_path, NULL); + DebugInfo actual_debug_info = compiler.build.debug_info; + compiler.build.debug_info = DEBUG_INFO_NONE; + GenContext *c = cmalloc(sizeof(GenContext)); gencontext_init(c, test_module, shared_context); gencontext_begin_module(c); @@ -1365,11 +1368,7 @@ INLINE GenContext *llvm_gen_tests(Module** modules, unsigned module_count, LLVMC llvm_gen_test_main(c); } - if (llvm_use_debug(c)) - { - LLVMDIBuilderFinalize(c->debug.builder); - LLVMDisposeDIBuilder(c->debug.builder); - } + compiler.build.debug_info = actual_debug_info; return c; } @@ -1401,6 +1400,8 @@ INLINE GenContext *llvm_gen_benchmarks(Module** modules, unsigned module_count, Path *benchmark_path = path_create_from_string("$benchmark", 10, INVALID_SPAN); Module *benchmark_module = compiler_find_or_create_module(benchmark_path, NULL); + DebugInfo actual_debug_info = compiler.build.debug_info; + compiler.build.debug_info = DEBUG_INFO_NONE; GenContext *c = cmalloc(sizeof(GenContext)); gencontext_init(c, benchmark_module, shared_context); gencontext_begin_module(c); @@ -1463,11 +1464,7 @@ INLINE GenContext *llvm_gen_benchmarks(Module** modules, unsigned module_count, llvm_gen_benchmark_main(c); } - if (llvm_use_debug(c)) - { - LLVMDIBuilderFinalize(c->debug.builder); - LLVMDisposeDIBuilder(c->debug.builder); - } + compiler.build.debug_info = actual_debug_info; return c; } diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index da8391198..c9305fa59 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -5739,12 +5739,12 @@ static bool sema_expr_analyse_sub(SemaContext *context, Expr *expr, Expr *left, Type *type = expr->type; expr_replace(expr, left); expr->type = type; - switch (left_type->type_kind) + switch (left->const_expr.const_kind) { - case ALL_INTS: + case CONST_INTEGER: expr->const_expr.ixx = int_sub(left->const_expr.ixx, right->const_expr.ixx); break; - case ALL_FLOATS: + case CONST_FLOAT: expr->const_expr.fxx = float_sub(left->const_expr.fxx, right->const_expr.fxx); break; default: diff --git a/test/test_suite/distinct/distinct_sub.c3t b/test/test_suite/distinct/distinct_sub.c3t new file mode 100644 index 000000000..3e15c283c --- /dev/null +++ b/test/test_suite/distinct/distinct_sub.c3t @@ -0,0 +1,58 @@ +distinct Foo = uint; + +macro @test($abc) +{ + return 1u << ($abc - 1); +} + +const Foo TEST = 5; +const Foo TEST_1 = @test(TEST); + +macro @test2($abc) +{ + return 1u << ($abc + 1); +} + +const Foo TEST_2 = @test2(TEST); + +macro @test3($abc) +{ + return 1u << ($abc * 2); +} + +const Foo TEST_3 = @test3(TEST); + +macro @test4($abc) +{ + return 1u << ($abc / 2); +} + +const Foo TEST_4 = @test4(TEST); + +macro @test5($abc) +{ + return 1u << ($abc % 2); +} + +const Foo TEST_5 = @test5(TEST); + +macro @test6($abc) +{ + return 1u << ($abc >> 1); +} + +const Foo TEST_6 = @test6(TEST); + +macro @test7($abc) +{ + return 1u << ($abc >> 1); +} + +const Foo TEST_7 = @test7(TEST); + +macro @test8($abc) +{ + return 1u << ($abc ^ 1); +} + +const Foo TEST_8 = @test8(TEST); diff --git a/test/unit/stdlib/io/path.c3 b/test/unit/stdlib/io/path.c3 index 84f6e85be..f3851d630 100644 --- a/test/unit/stdlib/io/path.c3 +++ b/test/unit/stdlib/io/path.c3 @@ -363,7 +363,7 @@ fn void! test_path_is_absolute() fn void! test_path_absolute() { $if env::WIN32: - assert(path::new_windows(`C:\abs`).absolute()!.str_view() == `C:\abs`); + assert(path::new_windows(`C:\abs`).new_absolute()!.str_view() == `C:\abs`); $else assert(path::new_posix("/").new_absolute()!.str_view() == "/"); assert(path::new_posix(".").new_absolute()!.str_view() == path::temp_cwd()!!.str_view());