From 7bb67b1fd0ca56a04778083f1a01583d839be9b1 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 6 Apr 2016 14:08:23 -0700 Subject: ability to compare function pointers at compile time --- src/analyze.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/analyze.cpp') diff --git a/src/analyze.cpp b/src/analyze.cpp index 99f1dac3c4..91fbddf717 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -2902,6 +2902,16 @@ static TypeTableEntry *analyze_bool_bin_op_expr(CodeGen *g, ImportTableEntry *im } else if (resolved_type->id == TypeTableEntryIdPureError) { 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) { answer = are_equal; } else if (bin_op_type == BinOpTypeCmpNotEq) { -- cgit v1.2.3