ability to compare function pointers at compile time
This commit is contained in:
parent
22ef416d4d
commit
7bb67b1fd0
|
@ -2902,6 +2902,16 @@ static TypeTableEntry *analyze_bool_bin_op_expr(CodeGen *g, ImportTableEntry *im
|
||||||
} else if (resolved_type->id == TypeTableEntryIdPureError) {
|
} else if (resolved_type->id == TypeTableEntryIdPureError) {
|
||||||
bool are_equal = op1_val->data.x_err.err == op2_val->data.x_err.err;
|
bool are_equal = op1_val->data.x_err.err == op2_val->data.x_err.err;
|
||||||
|
|
||||||
|
if (bin_op_type == BinOpTypeCmpEq) {
|
||||||
|
answer = are_equal;
|
||||||
|
} else if (bin_op_type == BinOpTypeCmpNotEq) {
|
||||||
|
answer = !are_equal;
|
||||||
|
} else {
|
||||||
|
zig_unreachable();
|
||||||
|
}
|
||||||
|
} else if (resolved_type->id == TypeTableEntryIdFn) {
|
||||||
|
bool are_equal = (op1_val->data.x_fn == op2_val->data.x_fn);
|
||||||
|
|
||||||
if (bin_op_type == BinOpTypeCmpEq) {
|
if (bin_op_type == BinOpTypeCmpEq) {
|
||||||
answer = are_equal;
|
answer = are_equal;
|
||||||
} else if (bin_op_type == BinOpTypeCmpNotEq) {
|
} else if (bin_op_type == BinOpTypeCmpNotEq) {
|
||||||
|
|
|
@ -522,6 +522,15 @@ fn max(T: type)(a: T, b: T) -> T {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#attribute("test")
|
||||||
|
fn constant_equal_function_pointers() {
|
||||||
|
const alias = empty_fn;
|
||||||
|
assert(@const_eval(empty_fn == alias));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn empty_fn() {}
|
||||||
|
|
||||||
|
|
||||||
fn assert(b: bool) {
|
fn assert(b: bool) {
|
||||||
if (!b) unreachable{}
|
if (!b) unreachable{}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user