I was working on a toy project and bumped into behavior that I don’t fully understand. In certain cases, @sizeOf doesn’t work as I’d expect, specifically when passing an anonymous struct:
Is there a reasonable explanation for this or I’m just holding it wrong?
My understanding is that anonymous structs supposed to act the same way as regular ones (with the exception that the compiler assigns their names).
You could assert the size of the anytype parameter is something you expect, wherever you actually use it in your real code, giving people an error if they try to use it with a wrong type in safe modes.
If you are checking information about a type it is comptime known, regardless of mode you will get a compile error. Modes are for runtime checks/optimisations not compile time.
I know you know this, just pointing that out for others.
Most likely the assertion can happen at comptime when it is based on some constant or calculation that fully depends on other comptime known things and in those case modes don’t matter.
My answer was more general, also including cases where part of the assert would be runtime known, for example when you assert that some runtime slice is smaller than the size of some array.