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

unable to put const struct declaration inside function #672

Closed
Hejsil opened this issue Jan 4, 2018 · 3 comments
Closed

unable to put const struct declaration inside function #672

Hejsil opened this issue Jan 4, 2018 · 3 comments
Labels
Milestone

Comments

@Hejsil
Copy link
Member

@Hejsil Hejsil commented Jan 4, 2018

Zig Version: 0.1.1.0cd63b28

Reproduce:

git clone https://github.com/Hejsil/pokemon-randomizer.git
cd pokemon-randomizer
zig build

zig: zig/src/ir.cpp:9693: IrInstruction* ir_get_var_ptr(IrAnalyze*, IrInstruction*, VariableTableEntry*, bool, bool): Assertion `var->value->type' failed.
@andrewrk andrewrk added this to the 0.2.0 milestone Jan 4, 2018
@andrewrk andrewrk added the bug label Jan 4, 2018
@andrewrk
Copy link
Member

@andrewrk andrewrk commented Jan 4, 2018

Here's a workaround:

--- a/src/nds.zig
+++ b/src/nds.zig
@@ -498,6 +498,16 @@ pub const Rom = struct {
     arm9_overlay: []u8,
     arm7_overlay: []u8,
 
+    // TODO: Comptime assert that BlockKind max value < @memberCount(BlockKind)
+    const BlockKind = enum(u8) {
+        Arm9        = 0,
+        Arm7        = 1,
+        Fnt         = 2,
+        Fat         = 3,
+        Arm9Overlay = 4,
+        Arm7Overlay = 5,
+    };
+
     pub fn fromStream(stream: &InStream, allocator: &Allocator) -> %Rom {
         var header: Header = undefined;
         var address: usize = 0;
@@ -506,16 +516,6 @@ pub const Rom = struct {
         %return header.validate();
         address += read;
 
-        // TODO: Comptime assert that BlockKind max value < @memberCount(BlockKind)
-        const BlockKind = enum(u8) {
-            Arm9        = 0,
-            Arm7        = 1,
-            Fnt         = 2,
-            Fat         = 3,
-            Arm9Overlay = 4,
-            Arm7Overlay = 5,
-        };
-
         const Block = struct {
             kind: BlockKind,
             offset: u32,

@andrewrk andrewrk changed the title Assertion fails in ir.cpp:9693 unable to put cost struct declaration inside function Jan 4, 2018
@andrewrk andrewrk changed the title unable to put cost struct declaration inside function unable to put const struct declaration inside function Jan 5, 2018
Hejsil added a commit to Hejsil/pokemon-randomizer that referenced this issue Jan 5, 2018
@andrewrk
Copy link
Member

@andrewrk andrewrk commented Jan 5, 2018

Small reproducer:

export fn entry() {
    const BlockKind = u32;

    const Block = struct {
        kind: BlockKind,
    };

    bogus;
}
$ zig build-obj test.zig
zig: /home/andy/dev/zig/src/ir.cpp:9693: IrInstruction* ir_get_var_ptr(IrAnalyze*, IrInstruction*, VariableTableEntry*, bool, bool): Assertion `var->value->type' failed.

@andrewrk andrewrk closed this in bb39e50 Jan 7, 2018
@andrewrk
Copy link
Member

@andrewrk andrewrk commented Jan 7, 2018

The crash is fixed and the code will work. The bad news is, structs declared inside functions get named after the function they're in (consider e.g. ArrayList(u32)). I'll open a new issue for this: #675

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants