You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A union of pointers of types, tagged with #shared_nil, treats a pointer to an empty struct type (pointer to struct {}) as a normalized nil value for the union.
This behavior is unexpected, and in my opinion contradicts the definition of the #shared_nil tag. My reasoning is that given type definition T :: struct {} the value ^T{} is not a pointer nil value nor a zero value for ^T
Operating System: macOS 14.5 (23F79)
Odin: dev-2025-01-nightly:2aae4cf
OS: macOS Unknown
CPU: Apple M1 Pro
RAM: 32768 MiB
Backend: LLVM 18.1.8
Expected Behavior
The following program should be able to run to a successful termination
package main
Type_A :: struct { value : int }
Type_B :: struct { }
Union_Of_Pointers :: union #shared_nil {
^Type_A,
^Type_B,
}
main :: proc() {
p : Union_Of_Pointers
assert(p == nil)
p = new(Type_A)
assert(p != nil)
p = new(Type_B)
assert(p != nil)
}
Current Behavior
The first and second assertions checks passes but the third assertion fails where it should not
Steps to Reproduce
Copy the code snippet form the expected behavior section into a new odin file
run odin run .
The text was updated successfully, but these errors were encountered:
nb-ohad
changed the title
Unexpected behavior for #share_nil on union of pointer types
Unexpected behavior for #shared_nil on union of pointer types
Feb 26, 2025
Context
A union of pointers of types, tagged with
#shared_nil
, treats a pointer to an empty struct type (pointer tostruct {}
) as a normalized nil value for the union.This behavior is unexpected, and in my opinion contradicts the definition of the
#shared_nil
tag. My reasoning is that given type definitionT :: struct {}
the value^T{}
is not a pointer nil value nor a zero value for^T
Operating System: macOS 14.5 (23F79)
Odin: dev-2025-01-nightly:2aae4cf
OS: macOS Unknown
CPU: Apple M1 Pro
RAM: 32768 MiB
Backend: LLVM 18.1.8
Expected Behavior
The following program should be able to run to a successful termination
Current Behavior
The first and second assertions checks passes but the third assertion fails where it should not
Steps to Reproduce
odin run .
The text was updated successfully, but these errors were encountered: