diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2023-06-14 12:05:34 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-14 12:05:34 +0100 |
| commit | 2149afabe1bf099b916b7f263e5b2ea45d987639 (patch) | |
| tree | 3dc80b5c6e38ecdcce53e6246d7628a4878276e0 | |
| parent | fc4a5e61c27467b30a421bceb7d21ac29ef8468e (diff) | |
| parent | ec32967daab5136fc2518f4068e7007e265c4e92 (diff) | |
Merge pull request #2590 from inbelic/inbelic/fix-no_nil-variants-err
[check-type] fix faulty #no_nil variants error
| -rw-r--r-- | src/check_type.cpp | 6 | ||||
| -rwxr-xr-x | tests/issues/run.sh | 7 | ||||
| -rw-r--r-- | tests/issues/test_issue_2395.odin | 29 |
3 files changed, 42 insertions, 0 deletions
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"); } diff --git a/tests/issues/run.sh b/tests/issues/run.sh index bbcd6fb28..b0c43572f 100755 --- a/tests/issues/run.sh +++ b/tests/issues/run.sh @@ -6,6 +6,8 @@ pushd build ODIN=../../../odin COMMON="-collection:tests=../.." +NO_NIL_ERR="Error: " + set -x $ODIN test ../test_issue_829.odin $COMMON -file @@ -14,6 +16,11 @@ $ODIN test ../test_issue_2056.odin $COMMON -file $ODIN test ../test_issue_2087.odin $COMMON -file $ODIN build ../test_issue_2113.odin $COMMON -file -debug $ODIN test ../test_issue_2466.odin $COMMON -file +if [[ $($ODIN build ../test_issue_2395.odin $COMMON -file 2>&1 >/dev/null | grep -c "$NO_NIL_ERR") -eq 2 ]] ; then + echo "SUCCESSFUL 1/1" +else + echo "SUCCESSFUL 0/1" +fi set +x diff --git a/tests/issues/test_issue_2395.odin b/tests/issues/test_issue_2395.odin new file mode 100644 index 000000000..48e1ee516 --- /dev/null +++ b/tests/issues/test_issue_2395.odin @@ -0,0 +1,29 @@ +// Tests issue #2395 https://github.com/odin-lang/Odin/issues/2395 + +// Ensures that we no longer raise the faulty error for #no_nil unions when +// then are 2 variants with the polymorphic type. Also ensure that we raise +// exactly 2 errors from the invalid unions +package test_issues + +import "core:testing" + +ValidUnion :: union($T: typeid) #no_nil { + T, + f32, +} + +OtherValidUnion :: union($T: typeid, $S: typeid) #no_nil { + T, + S, +} + +InvalidUnion :: union($T: typeid) #no_nil { + T, +} + +OtherInvalidUnion :: union($T: typeid) #no_nil { + u8, +} + +main :: proc() { +} |