Merge pull request #6355 from louisnovy/fix-bit_set-parapoly-specialization

Fix bit_set parapoly specialization #6240
This commit is contained in:
Jeroen van Rijn
2026-03-02 12:59:48 +01:00
committed by GitHub
5 changed files with 28 additions and 0 deletions

View File

@@ -1501,6 +1501,11 @@ gb_internal bool is_polymorphic_type_assignable(CheckerContext *c, Type *poly, T
case Type_BitSet:
if (source->kind == Type_BitSet) {
if (!is_type_polymorphic(poly->BitSet.elem)) {
if (poly->BitSet.upper != source->BitSet.upper || poly->BitSet.lower != source->BitSet.lower) {
return false;
}
}
if (!is_polymorphic_type_assignable(c, poly->BitSet.elem, source->BitSet.elem, true, modify_type)) {
return false;
}

View File

@@ -1229,6 +1229,7 @@ gb_internal void check_bit_set_type(CheckerContext *c, Type *type, Type *named_t
ast_node(bs, BitSetType, node);
GB_ASSERT(type->kind == Type_BitSet);
type->BitSet.node = node;
type->BitSet.elem = t_invalid;
/* i64 const DEFAULT_BITS = cast(i64)(8*build_context.word_size); */
i64 const MAX_BITS = 128;

View File

@@ -21,6 +21,7 @@ set COMMON=-define:ODIN_TEST_FANCY=false -file -vet -strict-style -ignore-unused
..\..\..\odin test ..\test_issue_4210.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_4364.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_4584.odin %COMMON% || exit /b
..\..\..\odin build ..\test_issue_2395.odin %COMMON% 2>&1 | find /c "Error:" | findstr /x "2" || exit /b
..\..\..\odin build ..\test_issue_5043.odin %COMMON% || exit /b
..\..\..\odin build ..\test_issue_5097.odin %COMMON% || exit /b
..\..\..\odin build ..\test_issue_5097-2.odin %COMMON% || exit /b
@@ -29,6 +30,7 @@ set COMMON=-define:ODIN_TEST_FANCY=false -file -vet -strict-style -ignore-unused
..\..\..\odin test ..\test_issue_6068.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_6101.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_6165.odin %COMMON% || exit /b
..\..\..\odin build ..\test_issue_6240.odin %COMMON% 2>&1 | find /c "Error:" | findstr /x "3" || exit /b
@echo off

View File

@@ -36,6 +36,12 @@ $ODIN test ../test_issue_5699.odin $COMMON
$ODIN test ../test_issue_6068.odin $COMMON
$ODIN test ../test_issue_6101.odin $COMMON
$ODIN test ../test_issue_6165.odin $COMMON
if [[ $($ODIN build ../test_issue_6240.odin $COMMON 2>&1 >/dev/null | grep -c "Error:") -eq 3 ]] ; then
echo "SUCCESSFUL 1/1"
else
echo "SUCCESSFUL 0/1"
exit 1
fi
set +x
popd

View File

@@ -0,0 +1,14 @@
// Tests issue #6240 https://github.com/odin-lang/Odin/issues/6240
package test_issues
// should error - N=10 does not match bit_set range 0..<5
foo :: proc($N: int, b: $B/bit_set[0 ..< N]) {}
// should error without segfaulting - undefined identifier in bit_set range
bar :: proc(b: $B/bit_set[0 ..< asdf]) {}
main :: proc() {
b: bit_set[0 ..< 5]
foo(10, b)
bar(bit_set[0 ..< 1]{})
}