diff --git a/spec/compiler/lexer/lexer_spec.cr b/spec/compiler/lexer/lexer_spec.cr index aa9eaf3e06c8..8575f6e1c14b 100644 --- a/spec/compiler/lexer/lexer_spec.cr +++ b/spec/compiler/lexer/lexer_spec.cr @@ -362,6 +362,9 @@ describe "Lexer" do assert_syntax_error "0o200_i8", "0o200 doesn't fit in an Int8" assert_syntax_error "0b10000000_i8", "0b10000000 doesn't fit in an Int8" + assert_syntax_error "0b11_f32", "binary float literal is not supported" + assert_syntax_error "0o73_f64", "octal float literal is not supported" + # 2**31 - 1 it_lexes_i32 [["0x7fffffff", "2147483647"], ["0o17777777777", "2147483647"], ["0b1111111111111111111111111111111", "2147483647"]] it_lexes_i32 [["0x7fffffff_i32", "2147483647"], ["0o17777777777_i32", "2147483647"], ["0b1111111111111111111111111111111_i32", "2147483647"]] diff --git a/src/compiler/crystal/syntax/lexer.cr b/src/compiler/crystal/syntax/lexer.cr index c8f65187a448..333fdadaa452 100644 --- a/src/compiler/crystal/syntax/lexer.cr +++ b/src/compiler/crystal/syntax/lexer.cr @@ -1284,6 +1284,13 @@ module Crystal raise("unexpected '_' in number", @token, (current_pos - start)) if peek_next_char == '_' break unless peek_next_char.in?('0'..'9') when 'i', 'u', 'f' + if current_char == 'f' && base != 10 + case base + when 2 then raise("binary float literal is not supported", @token, (current_pos - start)) + when 8 then raise("octal float literal is not supported", @token, (current_pos - start)) + end + break + end before_suffix_pos = current_pos @token.number_kind = consume_number_suffix next_char