Skip to content

Commit

Permalink
codegen+runtime: Work around AK's is<T>(U) refusing to work if T == U
Browse files Browse the repository at this point in the history
  • Loading branch information
alimpfard committed Oct 3, 2024
1 parent 17da9d0 commit d1fb6cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 10 additions & 0 deletions runtime/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,16 @@ T fail_comptime_call()
return declval<T>();
}

template<typename T, typename U>
constexpr static bool lenient_is(U value)
{
using NonRef = RemoveCVReference<U>;
if constexpr (IsSame<NonRef, T> || IsSame<NonRef, NonnullRefPtr<T>> || IsSame<NonRef, RefPtr<T>>)
return true;
else
return Jakt::is<T>(forward<U>(value));
}

template<typename T>
using UnderlyingClassTypeOf = typename Detail::UnderlyingClassTypeOf<RemoveCVReference<T>>::Type;
}
Expand Down
6 changes: 2 additions & 4 deletions selfhost/codegen.jakt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(')')
}
Expand Down Expand Up @@ -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") }
}
Expand Down

0 comments on commit d1fb6cc

Please sign in to comment.