add regression test for incorrect offset_of

This commit is contained in:
mo
2026-08-22 10:42:18 +12:00
parent 23bd3cd927
commit 7bb0bc353f
3 changed files with 29 additions and 0 deletions

View File

@@ -40,6 +40,7 @@ set COMMON=-define:ODIN_TEST_FANCY=false -file -vet -strict-style -ignore-unused
..\..\..\odin test ..\test_issue_6753.odin %COMMON% || exit /b
..\..\..\odin check ..\test_issue_6874.odin %COMMON% 2>&1 | find /c "Error:" | findstr /x "1" || exit /b
..\..\..\odin check ..\test_issue_6979.odin -no-entry-point %COMMON% || exit /b
..\..\..\odin test ..\test_issue_7008.odin %COMMON% || exit /b
..\..\..\odin check ..\test_issue_7012.odin -no-entry-point %COMMON% || exit /b
..\..\..\odin build ..\test_issue_7037.odin %COMMON% -o:none || exit /b
..\..\..\odin build ..\test_issue_7188.odin %COMMON% || exit /b

View File

@@ -88,6 +88,7 @@ else
exit 1
fi
$ODIN check ../test_issue_6979.odin -no-entry-point $COMMON_CHECK
$ODIN test ../test_issue_7008.odin $COMMON
$ODIN check ../test_issue_7012.odin -no-entry-point $COMMON_CHECK
$ODIN build ../test_issue_7037.odin $COMMON -o:none
$ODIN test ../test_issue_7356.odin $COMMON

View File

@@ -0,0 +1,27 @@
// Tests issue #7008 https://github.com/odin-lang/Odin/issues/7008
package test_issues
import "core:testing"
import "core:slice"
Bar :: struct {
p: ^Foo,
}
Maybe_Bar :: union {
Bar,
}
Foo :: struct {
bar: Maybe_Bar,
value: byte,
}
@(test)
test_offset_of_is_correct :: proc(t: ^testing.T) {
foo: Foo
foo.value = 42
bytes := slice.bytes_from_ptr(&foo, size_of(Foo))
testing.expect_value(t, bytes[offset_of(foo.value)], 42)
}