Skip to content

Commit e1aecff

Browse files
Hendiadyoin1awesomekling
authored andcommitted
LibJS: Fail compilation earlier when trying to emit with wrong arguments
This makes the compilation backtraces a lot nicer, and allows clangd to see the mistake as well.
1 parent af94e4c commit e1aecff

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Userland/Libraries/LibJS/Bytecode/Generator.h

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class Generator {
6868
};
6969

7070
template<typename OpType, typename... Args>
71+
requires(requires { OpType(declval<Args>()...); })
7172
void emit(Args&&... args)
7273
{
7374
VERIFY(!is_current_block_terminated());
@@ -81,6 +82,7 @@ class Generator {
8182
}
8283

8384
template<typename OpType, typename ExtraSlotType, typename... Args>
85+
requires(requires { OpType(declval<Args>()...); })
8486
void emit_with_extra_slots(size_t extra_slot_count, Args&&... args)
8587
{
8688
VERIFY(!is_current_block_terminated());
@@ -96,12 +98,14 @@ class Generator {
9698
}
9799

98100
template<typename OpType, typename... Args>
101+
requires(requires { OpType(declval<Args>()...); })
99102
void emit_with_extra_operand_slots(size_t extra_operand_slots, Args&&... args)
100103
{
101104
emit_with_extra_slots<OpType, Operand>(extra_operand_slots, forward<Args>(args)...);
102105
}
103106

104107
template<typename OpType, typename... Args>
108+
requires(requires { OpType(declval<Args>()...); })
105109
void emit_with_extra_value_slots(size_t extra_operand_slots, Args&&... args)
106110
{
107111
emit_with_extra_slots<OpType, Value>(extra_operand_slots, forward<Args>(args)...);

0 commit comments

Comments
 (0)