From ec32967daab5136fc2518f4068e7007e265c4e92 Mon Sep 17 00:00:00 2001 From: finn Date: Tue, 13 Jun 2023 22:07:01 +0200 Subject: [check-type] fix faulty #no_nil variants error - when checking the variants of a union type we will skip adding the variants if we have an unspecialized polymorphic, hence our union_type variants will be empty and have a count of 0 - so when checking if we violate the #no_nil error, if we are in the unspecialized polymorphic case and there exists at least one variant in the original variants then we should not raise this error - test checks that we do not raise the error anymore, and that we still detect the #no_nil error in the described circumstances --- src/check_type.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/check_type.cpp') diff --git a/src/check_type.cpp b/src/check_type.cpp index bbfc25a12..a69dcdadc 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -729,6 +729,12 @@ gb_internal void check_union_type(CheckerContext *ctx, Type *union_type, Ast *no union_type->Union.kind = ut->kind; switch (ut->kind) { case UnionType_no_nil: + if (union_type->Union.is_polymorphic && poly_operands == nullptr) { + GB_ASSERT(variants.count == 0); + if (ut->variants.count != 1) { + break; + } + } if (variants.count < 2) { error(ut->align, "A union with #no_nil must have at least 2 variants"); } -- cgit v1.2.3