-
-
Save lmb/f5444ac96b7e3d0ab860682315cad5f4 to your computer and use it in GitHub Desktop.
zig comptime return
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn makeToken(comptime id: Identifier, comptime data: []const u8) []const u8 { | |
comptime { | |
assert(data.len < longFormMin); | |
return makeIdentifier(id) ++ []u8{ | |
@truncate(u8, data.len), | |
} ++ data; | |
} | |
} | |
fn makeIdentifier(comptime id: Identifier) []const u8 { | |
comptime { | |
const number = id.tag.number(); | |
assert(number < multipartNumber); | |
return []u8{ | |
u8(@enumToInt(id.tag.class()))<<6 | u8(@enumToInt(id.encoding))<<5 | @truncate(u8, number), | |
}; | |
} | |
} | |
test "bloop" { | |
comptime const data = makeToken(A, []u8{0}); // error here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment