aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-07-13 12:34:42 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-07-13 12:34:42 -0400
commit5354d1f5fc496beb8313488ea1690e02e9c630fa (patch)
tree4b46b803efbc09944d2a0cb47904b452ea666fbd /src/ir.cpp
parentac096c294976b7cb6433a7939adcd664af770201 (diff)
downloadzig-5354d1f5fc496beb8313488ea1690e02e9c630fa.tar.gz
zig-5354d1f5fc496beb8313488ea1690e02e9c630fa.zip
allow == for comparing optional pointers
closes #658
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index eb62cc8bdf..f452ef43e0 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -11147,7 +11147,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
if (type_is_invalid(resolved_type))
return resolved_type;
-
+ bool operator_allowed;
switch (resolved_type->id) {
case TypeTableEntryIdInvalid:
zig_unreachable(); // handled above
@@ -11156,6 +11156,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdInt:
case TypeTableEntryIdFloat:
+ operator_allowed = true;
break;
case TypeTableEntryIdBool:
@@ -11170,19 +11171,8 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
case TypeTableEntryIdBoundFn:
case TypeTableEntryIdArgTuple:
case TypeTableEntryIdPromise:
- if (!is_equality_cmp) {
- ir_add_error_node(ira, source_node,
- buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));
- return ira->codegen->builtin_types.entry_invalid;
- }
- break;
-
case TypeTableEntryIdEnum:
- if (!is_equality_cmp) {
- ir_add_error_node(ira, source_node,
- buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));
- return ira->codegen->builtin_types.entry_invalid;
- }
+ operator_allowed = is_equality_cmp;
break;
case TypeTableEntryIdUnreachable:
@@ -11190,12 +11180,18 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
case TypeTableEntryIdStruct:
case TypeTableEntryIdUndefined:
case TypeTableEntryIdNull:
- case TypeTableEntryIdOptional:
case TypeTableEntryIdErrorUnion:
case TypeTableEntryIdUnion:
- ir_add_error_node(ira, source_node,
- buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));
- return ira->codegen->builtin_types.entry_invalid;
+ operator_allowed = false;
+ break;
+ case TypeTableEntryIdOptional:
+ operator_allowed = is_equality_cmp && get_codegen_ptr_type(resolved_type) != nullptr;
+ break;
+ }
+ if (!operator_allowed) {
+ ir_add_error_node(ira, source_node,
+ buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));
+ return ira->codegen->builtin_types.entry_invalid;
}
IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);