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

Can't use anonymous struct literal as default value for struct #3672

Closed
heidezomp opened this issue Nov 12, 2019 · 1 comment
Closed

Can't use anonymous struct literal as default value for struct #3672

heidezomp opened this issue Nov 12, 2019 · 1 comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@heidezomp
Copy link
Contributor

I'm trying to use an anonymous struct literal (which is a super cool feature btw 😄) to provide a default value for a struct field:

const Foo = struct {
    bar: Bar = .{ .a = 3 },
};

const Bar = struct {
    a: u32,
};

pub fn main() void {
    const foo: Foo = .{};
}

which results in the following error:

/home/heidezomp/Code/grot/foo.zig:2:17: error: expected type 'Bar', found 'struct:2:17'
    bar: Bar = .{ .a = 3 },
                ^
/home/heidezomp/Code/grot/foo.zig:5:13: note: Bar declared here
const Bar = struct {
            ^
/home/heidezomp/Code/grot/foo.zig:2:17: note: struct:2:17 declared here
    bar: Bar = .{ .a = 3 },
                ^
/home/heidezomp/Code/grot/foo.zig:10:23: note: referenced here
    const foo: Foo = .{};
@andrewrk andrewrk added this to the 0.6.0 milestone Nov 14, 2019
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Nov 14, 2019
@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. and removed bug Observed behavior contradicts documented or intended behavior labels Dec 6, 2019
@andrewrk
Copy link
Member

andrewrk commented Dec 6, 2019

Now gives:

test.zig:2:17: error: TODO: type coercion of anon struct literal to struct
    bar: Bar = .{ .a = 3 },
                ^
test.zig:10:23: note: referenced here
    const foo: Foo = .{};
                      ^

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. stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

2 participants