Commit 925f710852

momumi <57862114+momumi@users.noreply.github.com>
2020-03-15 04:05:24
make parsing `0.0_e1` an error
1 parent 7aac21c
Changed files (2)
src/tokenizer.cpp
@@ -1229,6 +1229,10 @@ void tokenize(Buf *buf, Tokenization *out) {
                         break;
                     }
                     if (is_exponent_signifier(c, t.radix)) {
+                        if (t.is_trailing_underscore) {
+                            invalid_char_error(&t, c);
+                            break;
+                        }
                         if (t.radix != 16 && t.radix != 10) {
                             invalid_char_error(&t, c);
                         }
@@ -1296,6 +1300,10 @@ void tokenize(Buf *buf, Tokenization *out) {
                         break;
                     }
                     if (is_exponent_signifier(c, t.radix)) {
+                        if (t.is_trailing_underscore) {
+                            invalid_char_error(&t, c);
+                            break;
+                        }
                         t.state = TokenizeStateFloatExponentUnsigned;
                         t.radix = 10; // exponent is always base 10
                         break;
test/compile_errors.zig
@@ -485,6 +485,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
         "tmp.zig:2:23: error: invalid character: '_'",
     });
 
+    cases.add("invalid underscore placement in float literal - 14",
+        \\fn main() void {
+        \\    var bad: f128 = 0x0.0_p1;
+        \\})
+    , &[_][]const u8{
+        "tmp.zig:2:27: error: invalid character: 'p'",
+    });
+
     cases.add("var args without c calling conv",
         \\fn foo(args: ...) void {}
         \\comptime {