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

Crash when getting array item, for array of struct containing fields with undeclared types #1186

Closed
dbandstra opened this Issue Jul 2, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@dbandstra
Contributor

dbandstra commented Jul 2, 2018

pub const Item = struct{
  field: SomeNonexistentType,
};

pub var items: [100]Item = undefined;
pub var item: Item = undefined;

test "" {
  const a = items[0]; // this crashes
  // const b = &items[0]; // this crashes
  // for (items) |x| {} // this crashes
  // const c = items; // this gives a proper error message
  // const d = &item; // this gives a proper error message
}

Crashes with the message:

zig/src/analyze.cpp:386: TypeTableEntry* get_pointer_to_type_extra(CodeGen*, TypeTableEntry*, bool, bool, PtrLen, uint32_t, uint32_t, uint32_t): Assertion `!type_is_invalid(child_type)' failed.
@isaachier

This comment has been minimized.

Contributor

isaachier commented Jul 2, 2018

You mean it shouldn't crash, but it should fail to compile with an error message?

@dbandstra

This comment has been minimized.

Contributor

dbandstra commented Jul 2, 2018

Yeah, that's what I meant. It should be producing the use of undeclared identifier 'SomeNonexistentType' error message (this is what happens with the last two commented out lines in my code paste).

@dbandstra

This comment has been minimized.

Contributor

dbandstra commented Sep 5, 2018

On latest master, the error message is now this:

zig: /home/dbandstra/zig/src/result.hpp:16: void assertNoError(Error): Assertion `err == ErrorNone' failed.

@andrewrk andrewrk closed this in a76a724 Sep 5, 2018

@andrewrk andrewrk modified the milestones: 0.4.0, 0.3.0 Sep 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment