#Using @TypeOf on error unions

1 messages · Page 1 of 1 (latest)

uncut minnow
#

Got it down to const type = @TypeOf(error.BadValue)

outer kestrel
#

Is type not a keyword Sorry was second guessing myself. type is a keyword so you're likely hitting the error because you're shadowing the keyword

#

You're also not using the variable, so zig will error on that.

pub fn main() void {
  const foo = @TypeOf(error.BadValue);
  _ = foo;
}```Compiles for me on master
uncut minnow
#

hmmm. still coredumps for me on that program

outer kestrel
#

What version of zig are you using?

uncut minnow
#

Ah, im building from 3cb987f5a575bc5871459805a86640ba1a2d7cae. Im one commit off true master

#

Don't see how spirv will change much. I was coredumping since a few days ago. Tried updating some more. Only recently got it compiled with debug info.

#

I'll submit a github bug, was curious if that was invalid though, sounds like it shouldn't be. thanks!

outer kestrel
#

Turns out I'm actually pretty behind as well haha. I thought I updated recently but I must have been imagining things. I'm on 0.12.0-dev.3142+9e402704e. Maybe there was a regression?

uncut minnow
#

Ah maybe. Only started using zig again last week. Last builds I had before that were from ages ago.

maiden mural
#

Can you please provide an actual reproduction? The code is missing a semicolon and zig build test.zig is not usually a valid command.

uncut minnow
#

Updated. It is quite literally saving const t = @TypeOf(error.BadValue) as test.zig and doing zig build test.zig

#

Found it when adding @TypeOf(error union) caused the compiler to segfault on much more complex code

maiden mural
#
$ zig build test.zig
no step named 'test.zig'
  access the help menu with 'zig build -h'
#

I guess this is more accurate

$ zig build test.zig
info: initialize build.zig template file with 'zig init'
info: see 'zig --help' for more options
error: no build.zig file found, in the current directory or any parent directories
uncut minnow
#

Ohhhh my bad, forgot about build.zig (as I said haven't used zig in a while)

maiden mural
#

sorry, I legit didn't expect you to have a build step named after a file

uncut minnow
#

It was auto-generated for me. Totally coincedental lol

#

Hence why I forgot abou tit

maiden mural
#

anyway I'm still getting the first output, we need the actual command you are running

#

Maybe you are actually getting a crash in src/main.zig but editing test.zig for example?

uncut minnow
#

Ya im not sure what the build.zig is doing ngl. Going to paste the actual file that I first started coredumping on since I gotta go to bed soon.

maiden mural
#

we need the exact contents of the files and the exact command that is crashing

uncut minnow
#

Yep copying it over now

#

Thought I had it reproducible but forgot about build.zig that is my bad

maiden mural
#

For the future, the best reproducer is zig build-obj file.zig where file.zig contains the fewest extern functions or comptime blocks that reproduce the issue, this cuts out a lot of possible interference from bugs compiling the startup code

uncut minnow
#

Just tried it on the file that is causing issues, seems to work. Only coredumps on zig test src/once.zig. Gonna copy paste it for now as is. Will help y'all in the morning

maiden mural
#

The trick if you need a function with argument and return types that aren't compatible with extern is fn entry() void {} comptime { _ = &entry; }