#[solved] Porting `@typeInfo` to `0.15.1`

1 messages · Page 1 of 1 (latest)

radiant sandal
#
  const T = @typeInfo([]const u8);
  try check.ok(T.pointer.size == @import("std").builtin.Type.pointer.size.slice);
source.test.zig:24:65: error: type '@typeInfo(builtin.Type).@"union".tag_type.?' does not support field access
  try check.ok(T.pointer.size == @import("std").builtin.Type.pointer.size.slice);
                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~

I have this type checking code that I was using for unit testing in 0.13-0.14
I'm porting it to 0.15.1, but I'm getting new errors since the typeinfo API changed lately.
What is this meant to look like with the new typeinfo fields? 🤔

sour citrus
#

try just T.pointer.size == .slice

radiant sandal
#

Thanks!
I think I was originally accessing the type, not the field, and that's why it was complaining
That fixed it, tyty

#

[solved] Porting @typeInfo to 0.15.1

sour citrus
#

i think if you want the fully qualified version its std.builtin.Type.Pointer.Size.slice, lowercase is for fields

radiant sandal
#

gotcha

sour citrus
#

but of course .slice is much nicer

radiant sandal
#

Shorter, but less explicit. For unit testing, I think I prefer the explicit one 🙂
But yea, I see what you mean

#

I think the issue was accessing .Slice not .slice at the end

sour citrus
#

to be specific, the error is from trying to do field access on std.builtin.Type.pointer, which is an enum (the tag type of Type)