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

Setting optionals to undefined defaults to null in debug mode #8333

Open
fengb opened this issue Mar 22, 2021 · 1 comment
Open

Setting optionals to undefined defaults to null in debug mode #8333

fengb opened this issue Mar 22, 2021 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@fengb
Copy link
Contributor

fengb commented Mar 22, 2021

If we do a simple undefined optional (var foo: ?u32 = undefined;), this gets converted to null only in debug mode: https://zig.godbolt.org/z/5a6ca8bz8. This is correctly set to 0xAAAA in release-safe.

This feels like a footgun as simple testing will trigger wrong assumptions.

@Vexu Vexu added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Mar 22, 2021
@Vexu Vexu added this to the 0.9.0 milestone Mar 22, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@Vexu
Copy link
Member

Vexu commented Dec 2, 2021

This happens with error unions too, just had a confusing debugging session because of it.

test {
    var a: anyerror!u32 = undefined;
    _ = a catch unreachable;
}

RetroDev256 added a commit to RetroDev256/zig that referenced this issue Sep 9, 2024
RetroDev256 added a commit to RetroDev256/zig that referenced this issue Sep 9, 2024
RetroDev256 added a commit to RetroDev256/zig that referenced this issue Sep 9, 2024
RetroDev256 added a commit to RetroDev256/zig that referenced this issue Sep 9, 2024
RetroDev256 added a commit to RetroDev256/zig that referenced this issue Sep 9, 2024
RetroDev256 added a commit to RetroDev256/zig that referenced this issue Sep 10, 2024
RetroDev256 added a commit to RetroDev256/zig that referenced this issue Sep 10, 2024
RetroDev256 added a commit to RetroDev256/zig that referenced this issue Nov 24, 2024
alexrp pushed a commit to RetroDev256/zig that referenced this issue Feb 5, 2025
RetroDev256 added a commit to RetroDev256/zig that referenced this issue Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants