diff --git a/spec/compiler/lexer/lexer_spec.cr b/spec/compiler/lexer/lexer_spec.cr index 6a858baeaae8..612e16512da7 100644 --- a/spec/compiler/lexer/lexer_spec.cr +++ b/spec/compiler/lexer/lexer_spec.cr @@ -321,6 +321,9 @@ describe "Lexer" do assert_syntax_error "4F64", "unexpected token: F64" assert_syntax_error "0F32", "unexpected token: F32" + assert_syntax_error ".42", ".1 style number literal is not supported, put 0 before dot" + assert_syntax_error "-.42", ".1 style number literal is not supported, put 0 before dot" + it "lexes not instance var" do lexer = Lexer.new "!@foo" token = lexer.next_token diff --git a/src/compiler/crystal/syntax/lexer.cr b/src/compiler/crystal/syntax/lexer.cr index 708a58b63e30..fbaf61bdb159 100644 --- a/src/compiler/crystal/syntax/lexer.cr +++ b/src/compiler/crystal/syntax/lexer.cr @@ -636,6 +636,8 @@ module Crystal when '~' next_char :"~" when '.' + line = @line_number + column = @column_number case next_char when '.' case next_char @@ -644,6 +646,8 @@ module Crystal else @token.type = :".." end + when .ascii_number? + raise ".1 style number literal is not supported, put 0 before dot", line, column else @token.type = :"." end