From d1fb6cc0e91e3f0164a412b5cdebe7183ad798f5 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Thu, 3 Oct 2024 21:30:09 +0200 Subject: [PATCH] codegen+runtime: Work around AK's is(U) refusing to work if T == U --- runtime/lib.h | 10 ++++++++++ selfhost/codegen.jakt | 6 ++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/runtime/lib.h b/runtime/lib.h index 2a4e8f32b..9980ac5e7 100644 --- a/runtime/lib.h +++ b/runtime/lib.h @@ -395,6 +395,16 @@ T fail_comptime_call() return declval(); } +template +constexpr static bool lenient_is(U value) +{ + using NonRef = RemoveCVReference; + if constexpr (IsSame || IsSame> || IsSame>) + return true; + else + return Jakt::is(forward(value)); +} + template using UnderlyingClassTypeOf = typename Detail::UnderlyingClassTypeOf>::Type; } diff --git a/selfhost/codegen.jakt b/selfhost/codegen.jakt index dee4a4ff6..108cddd27 100644 --- a/selfhost/codegen.jakt +++ b/selfhost/codegen.jakt @@ -2940,8 +2940,6 @@ struct CodeGenerator { }) } UnaryOp(expr, op, type_id) => { - - match op { PreIncrement => .codegen_prefix_unary(expr, cpp_operator: "++", output, syntactically_self_contained) PreDecrement => .codegen_prefix_unary(expr, cpp_operator: "--", output, syntactically_self_contained) @@ -2980,7 +2978,7 @@ struct CodeGenerator { } else => .codegen_type(type_id) } - output.appendff("is<{}>(", is_type) + output.appendff("JaktInternal::lenient_is<{}>(", is_type) .codegen_expression(expr, output) output.append(')') } @@ -3754,7 +3752,7 @@ struct CodeGenerator { } } ClassInstance(type: type_id) => { - output.appendff("is<{}>(__jakt_enum_value.ptr())", .codegen_type_possibly_as_namespace(type_id, as_namespace: true)) + output.appendff("JaktInternal::lenient_is<{}>(__jakt_enum_value.ptr())", .codegen_type_possibly_as_namespace(type_id, as_namespace: true)) } CatchAll => { .compiler.panic("catch all has no condition, should be emitted separately") } }