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

Runtime slice of zero-sized pointer assigned to _ yields strange compile error #6937

Closed
SpexGuy opened this issue Nov 2, 2020 · 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

@SpexGuy
Copy link
Contributor

SpexGuy commented Nov 2, 2020

// repro.zig
export fn foo() void {
    var x: usize = 4;
    _ = @as([*]void, undefined)[0..x];
}
<source>:5:32: error: expected type 'void', found '[]void'
    _ = @as([*]void, undefined)[0..x];
                               ^

Replacing _ with var y or const y fixes the error.

@SpexGuy SpexGuy added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Nov 3, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 3, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@mikdusan
Copy link
Member

mikdusan commented Jan 7, 2023

with latest compiler:

  • compiler no longer errors
  • appears this was fixed between 0.9.1 and 0.10.0
repro.zig
export fn foo() void {
    var x: usize = 4;
    _ = @as([*]void, undefined)[0..x];
}
$ uname -a
Linux archlinux 6.1.2-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 31 Dec 2022 17:40:35 +0000 x86_64 GNU/Linux

$ zig version
0.11.0-dev.1247+87b223428

$ zig build-obj repro.zig
# no stdout/stderr (good)

@mikdusan mikdusan closed this as completed Jan 7, 2023
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Jan 8, 2023
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

No branches or pull requests

3 participants