Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior for #shared_nil on union of pointer types #4882

Open
nb-ohad opened this issue Feb 26, 2025 · 1 comment
Open

Unexpected behavior for #shared_nil on union of pointer types #4882

nb-ohad opened this issue Feb 26, 2025 · 1 comment

Comments

@nb-ohad
Copy link

nb-ohad commented Feb 26, 2025

Context

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

  1. Copy the code snippet form the expected behavior section into a new odin file
  2. run odin run .
@nb-ohad 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
@nb-ohad
Copy link
Author

nb-ohad commented Feb 26, 2025

Might be related to: #1202

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant