`sizeof` doesn't accept types other than an unqualified type identifier
import "std.um"
fn main() {
printf("%llv\n", sizeof(std::Err)) // Type cast or composite literal or enumeration constant expected
}
Not only that:
sizeof([5]int)
sizeof([]int)
sizeof(map[str]int)
sizeof(^int) // Not necessary but for consistency
sizeof(struct {x, y, z: int})
sizeof(fn (a: int): int)
sizeof(enum {a; b; c})
sizeof(interface {})
@ske2004 Ah, you're right! It doesn't accept anything except an unqualified type name, because otherwise it would be hard to distinguish a type from an expression (an infinite lookup needed?)
The workaround is simple, though:
import "std.um"
fn main() {
type E = std::Err
printf("%llv\n", sizeof(E))
}
@vtereshkov can types be expressions?
@ske2004 No, they cannot. Of what type could they be? Type type?
@vtereshkov Unironically yes
@ske2004 We discussed this idea on Discord 1.5 years ago and were not very excited:
https://discord.com/channels/846663478873030666/846663478873030672/1140395255322136719
@vtereshkov This would an implementation detail. Something like std::Err would be of type type, that can be passed to builtins. It's more so to unify the parsing of types and normal expressions.
Type inference and extraction is somewhat unrelated.