@@ -11147,7 +11147,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
11147
11147
if (type_is_invalid(resolved_type))
11148
11148
return resolved_type;
11149
11149
11150
-
11150
+ bool operator_allowed;
11151
11151
switch (resolved_type->id) {
11152
11152
case TypeTableEntryIdInvalid:
11153
11153
zig_unreachable(); // handled above
@@ -11156,6 +11156,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
11156
11156
case TypeTableEntryIdComptimeInt:
11157
11157
case TypeTableEntryIdInt:
11158
11158
case TypeTableEntryIdFloat:
11159
+ operator_allowed = true;
11159
11160
break;
11160
11161
11161
11162
case TypeTableEntryIdBool:
@@ -11170,32 +11171,27 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
11170
11171
case TypeTableEntryIdBoundFn:
11171
11172
case TypeTableEntryIdArgTuple:
11172
11173
case TypeTableEntryIdPromise:
11173
- if (!is_equality_cmp) {
11174
- ir_add_error_node(ira, source_node,
11175
- buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));
11176
- return ira->codegen->builtin_types.entry_invalid;
11177
- }
11178
- break;
11179
-
11180
11174
case TypeTableEntryIdEnum:
11181
- if (!is_equality_cmp) {
11182
- ir_add_error_node(ira, source_node,
11183
- buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));
11184
- return ira->codegen->builtin_types.entry_invalid;
11185
- }
11175
+ operator_allowed = is_equality_cmp;
11186
11176
break;
11187
11177
11188
11178
case TypeTableEntryIdUnreachable:
11189
11179
case TypeTableEntryIdArray:
11190
11180
case TypeTableEntryIdStruct:
11191
11181
case TypeTableEntryIdUndefined:
11192
11182
case TypeTableEntryIdNull:
11193
- case TypeTableEntryIdOptional:
11194
11183
case TypeTableEntryIdErrorUnion:
11195
11184
case TypeTableEntryIdUnion:
11196
- ir_add_error_node(ira, source_node,
11197
- buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));
11198
- return ira->codegen->builtin_types.entry_invalid;
11185
+ operator_allowed = false;
11186
+ break;
11187
+ case TypeTableEntryIdOptional:
11188
+ operator_allowed = is_equality_cmp && get_codegen_ptr_type(resolved_type) != nullptr;
11189
+ break;
11190
+ }
11191
+ if (!operator_allowed) {
11192
+ ir_add_error_node(ira, source_node,
11193
+ buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));
11194
+ return ira->codegen->builtin_types.entry_invalid;
11199
11195
}
11200
11196
11201
11197
IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);
0 commit comments