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

mod operator should narrow integer type #2143

Open
shawnl opened this issue Mar 30, 2019 · 4 comments
Open

mod operator should narrow integer type #2143

shawnl opened this issue Mar 30, 2019 · 4 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase.
Milestone

Comments

@shawnl
Copy link
Contributor

shawnl commented Mar 30, 2019

This should compile (except for the other error...):

pub fn main() void {
var c: u32 = 1235;
        return switch (c % 4) {
        0 => 0,
        1 => 1,
        2 => 2,
        3 => 3,
        };
}

But instead:

/home/shawn/projects/shared/switch.zig:3:16: error: switch must handle all possibilities
        return switch (c % 4) {
               ^
@andrewrk
Copy link
Member

This is planned. Related: #509

@andrewrk andrewrk added the enhancement Solving this issue will likely involve adding new logic or components to the codebase. label Mar 30, 2019
@andrewrk andrewrk added this to the 0.5.0 milestone Mar 30, 2019
@shawnl
Copy link
Contributor Author

shawnl commented Mar 30, 2019

I don't expect it to work without an else => unreachable when the mod is not a power of 2.

@shawnl
Copy link
Contributor Author

shawnl commented Mar 30, 2019

Actually, after reading #509 I think this is a bad idea. I wasn't thinking about when the second argument to the mod function isn't known compile-time (which means you can't narrow the type).

Oh, now I see it only applies in very few cases, where value-range-propagation can work. Yeah that is OK.

@shawnl shawnl closed this as completed Mar 30, 2019
@andrewrk
Copy link
Member

This is still planned.

@andrewrk andrewrk reopened this Mar 30, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Aug 30, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Jan 3, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 10, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase.
Projects
None yet
Development

No branches or pull requests

2 participants