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

stage2: if allows usize in condition, if the payload is discarded #13023

Closed
topolarity opened this issue Sep 30, 2022 · 3 comments
Closed

stage2: if allows usize in condition, if the payload is discarded #13023

topolarity opened this issue Sep 30, 2022 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@topolarity
Copy link
Contributor

Zig Version

0.10.0-dev.4189+17eea918a

Steps to Reproduce

test {
    if (@as(usize, 5)) |_| {}
}

Expected Behavior

Stage 1 does the right thing:

./test.zig:3:9: error: expected optional type, found 'usize'
    if (@as(usize, 5)) |_| {
        ^

Actual Behavior

All 1 tests passed.
@topolarity topolarity added the bug Observed behavior contradicts documented or intended behavior label Sep 30, 2022
@Vexu Vexu added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Sep 30, 2022
@Vexu Vexu added this to the 0.10.0 milestone Sep 30, 2022
@nektro
Copy link
Contributor

nektro commented Sep 30, 2022

this is because of the @as not usize

@nektro
Copy link
Contributor

nektro commented Sep 30, 2022

its not doing the optional check when the payload is a builtin. the following has the same result

test {
    if (@sin(5.0)) |_| {}
}

@Vexu
Copy link
Member

Vexu commented Oct 5, 2022

This issue also applies to error union conditions and while loops and has nothing to do with builtin functions and everything to do with is_non_err and is_non_null being valid for all types.

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 frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

4 participants