Skip to content

nullable type compiler error #1805

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
emekoi opened this issue Nov 28, 2018 · 9 comments
Closed

nullable type compiler error #1805

emekoi opened this issue Nov 28, 2018 · 9 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@emekoi
Copy link
Contributor

emekoi commented Nov 28, 2018

given the following code:

pub const Node = struct {
    children: []?Node,
    data: ?u8,

    fn new() Node {
        return Node {
            .children = undefined,
            .data = null,
        };
    }
};

trying to call Node.new() trips this assertion instead of providing a meaningful error message about how the type is recursive.

@andrewrk andrewrk added this to the 0.4.0 milestone Nov 29, 2018
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Nov 29, 2018
@emekoi
Copy link
Contributor Author

emekoi commented Nov 29, 2018

wait, isn't a slice basically a pointer with a length? so why is this type recursion?

@andrewrk
Copy link
Member

I don't know where you're getting the idea that this is type recursion, but if you're tripping an assertion then it's a compiler bug.

@emekoi emekoi changed the title better compiler message on recursive types nullable type compiler error Nov 29, 2018
@tgschultz
Copy link
Contributor

tgschultz commented Nov 29, 2018

The type is recursive. children is an array of Optional Nodes, each of which contains a children member that is an array of Optional Nodes, each of which contains an array of Optional Nodes, each of which...

You probably either meant children: [alphabet]?*Node (an array of Optional pointers to Node) or children: []?Node (a slice of Optional Nodes).

Also, in the code shown Self is never defined. Not sure if relevant, but if it is it might be related to #1483.

@emekoi
Copy link
Contributor Author

emekoi commented Nov 29, 2018

even when i change children to children: []?Node i still get a compiler error. children: []?*Node works though.

@andrewrk
Copy link
Member

That sounds like #1500

@suirad
Copy link
Contributor

suirad commented Nov 29, 2018

Unless this was cut from other code, .data also doesn't have a type.

@emekoi
Copy link
Contributor Author

emekoi commented Nov 29, 2018

so should i close this then?

@andrewrk
Copy link
Member

so should i close this then?

No, because it's a compiler bug.

pub const Node = struct {
    children: []?Node,
    data: ?u8,

    fn new() Node {
        return Node{
            .children = undefined,
            .data = null,
        };
    }
};

test "aoeu" {
    _ = Node.new();
}
zig: /home/andy/downloads/zig/src/analyze.cpp:2694: Error resolve_struct_alignment(CodeGen*, ZigType*): Assertion `field->type_entry != nullptr' failed.

@andrewrk
Copy link
Member

andrewrk commented Apr 6, 2019

Proposal to fix this: #2174

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
Projects
None yet
Development

No branches or pull requests

4 participants