aboutsummaryrefslogtreecommitdiff
path: root/src/check_type.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2020-02-01 11:10:28 +0000
committergingerBill <bill@gingerbill.org>2020-02-01 11:10:28 +0000
commit0f399a72941c7cebcb5ad0580a9d94d1a7a37ac0 (patch)
tree249d37e76b25472674b4a8e7cb8aabec1ba6ab02 /src/check_type.cpp
parent4bcb667e97fc84d3eb5d7d4df34d566baddfaa1c (diff)
Add `union #maybe`
Diffstat (limited to 'src/check_type.cpp')
-rw-r--r--src/check_type.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp
index f21c1563b..f21ffc956 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -748,11 +748,17 @@ void check_union_type(CheckerContext *ctx, Type *union_type, Ast *node, Array<Op
union_type->Union.variants = variants;
union_type->Union.no_nil = ut->no_nil;
+ union_type->Union.maybe = ut->maybe;
if (union_type->Union.no_nil) {
if (variants.count < 2) {
error(ut->align, "A union with #no_nil must have at least 2 variants");
}
}
+ if (union_type->Union.maybe) {
+ if (variants.count != 1) {
+ error(ut->align, "A union with #maybe must have at 1 variant, got %lld", cast(long long)variants.count);
+ }
+ }
if (ut->align != nullptr) {
i64 custom_align = 1;