aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2020-03-21 18:33:54 +0100
committerAndrew Kelley <andrew@ziglang.org>2020-03-21 20:54:05 -0400
commitdc79f181a56cad17f429bbb7fd176e49bf3d66da (patch)
tree4aa0c56887fb3f197b692d999c8a2771d984cca7 /src/ir.cpp
parentbeea478acc2491289ec3e3bbdcec3b68f65d6e62 (diff)
downloadzig-dc79f181a56cad17f429bbb7fd176e49bf3d66da.tar.gz
zig-dc79f181a56cad17f429bbb7fd176e49bf3d66da.zip
ir: Disallow comparison between enum literal and untagged enum
Closes #4770
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 531c1b2432..590b81d3be 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -16286,6 +16286,15 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
IrInstGen *union_val = op1->value->type->id == ZigTypeIdUnion ? op1 : op2;
IrInstGen *enum_val = op1->value->type->id == ZigTypeIdUnion ? op2 : op1;
+ if (!is_tagged_union(union_val->value->type)) {
+ ErrorMsg *msg = ir_add_error_node(ira, source_node,
+ buf_sprintf("comparison of union and enum literal is only valid for tagged union types"));
+ add_error_note(ira->codegen, msg, union_val->value->type->data.unionation.decl_node,
+ buf_sprintf("type %s is not a tagged union",
+ buf_ptr(&union_val->value->type->name)));
+ return ira->codegen->invalid_inst_gen;
+ }
+
ZigType *tag_type = union_val->value->type->data.unionation.tag_type;
assert(tag_type != nullptr);