Skip to content

Missing result locations for builtin types #16211

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

Closed
vesim987 opened this issue Jun 25, 2023 · 5 comments
Closed

Missing result locations for builtin types #16211

vesim987 opened this issue Jun 25, 2023 · 5 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@vesim987
Copy link
Contributor

Zig Version

0.11.0-dev.3826+7a197f124

Steps to Reproduce and Observed Behavior

While porting microzig to latest zig version I have found couple of missing result locations for builtins.

const Foo = struct {
    bar: u32,
};

const MyStruct = struct {
    foo: *Foo,
};

export fn issue_1() void {
    _ = MyStruct{
        .foo = &.{
            .bar = @intCast(20),
        },
    };
}

fn do_something(_: *Foo) void {}

export fn issue_2() void {
    do_something(&.{
        .bar = @intCast(20),
    });
}


export fn isse_3 () void {
  _ = [1]u16{
      @intCast(20),
  };
}

It also applies to other builtins.

Expected Behavior

Every example to compile.

@vesim987 vesim987 added the bug Observed behavior contradicts documented or intended behavior label Jun 25, 2023
@nektro
Copy link
Contributor

nektro commented Jun 25, 2023

issue_1 and issue_2 create a *const Foo in their bodies, so i would not expect those to compile

@mlugg
Copy link
Member

mlugg commented Jun 26, 2023

It makes sense that issue_1 and issue_2 don't work, but perhaps we want them to. issue_3 should certainly work however - #16226 is technically a duplicate but we can track that issue there for separation.

@andrewrk andrewrk added this to the 0.11.1 milestone Jul 22, 2023
@andrewrk andrewrk added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Jul 22, 2023
@perillo
Copy link
Contributor

perillo commented Jan 29, 2024

@mlugg, Issue #16226 has been closed.

I suspect that the problem is no longer "missing result locations", but about "how to cast away constness".

@mlugg
Copy link
Member

mlugg commented Jan 29, 2024

Yes, #16226 has been closed because the issue_3 snippet now works. The other issues detailed here were resolved by #16512, so this issue can now be closed. The constness cast failure you noticed is just a minor bug in the given test case, unrelated to the issue at hand.

@mlugg mlugg closed this as completed Jan 29, 2024
@mlugg mlugg modified the milestones: 0.11.1, 0.12.0 Jan 29, 2024
@perillo
Copy link
Contributor

perillo commented Jan 29, 2024

The constness cast failure you noticed is just a minor bug in the given test case, unrelated to the issue at hand.

What I assumed from your comment:

It makes sense that issue_1 and issue_2 don't work, but perhaps we want them to

is that since the destination is not a const pointer, then the compiler should automatically cast away the constness, since it is safe.

@andrewrk andrewrk modified the milestones: 0.11.1, 0.12.0 Jan 29, 2024
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

5 participants