parse_float: Error when a float is attempted to be parsed into an invalid type

Co-authored-by: Ryan Liptak <squeek502@hotmail.com>
This commit is contained in:
Jayden 2023-05-08 06:42:24 -04:00 committed by GitHub
parent 5a3eca5d4c
commit b18b4db709
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,6 +12,14 @@ pub const ParseFloatError = error{
};
pub fn parseFloat(comptime T: type, s: []const u8) ParseFloatError!T {
if (@typeInfo(T) != .Float) {
@compileError("Cannot parse a float into a non-floating point type.");
}
if (T == f80) {
@compileError("TODO support parsing float to f80");
}
if (s.len == 0) {
return error.InvalidCharacter;
}