Skip to content

Commit

Permalink
Remove oct/bin floating point literals (#12687)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlobCodes committed Dec 15, 2022
1 parent 1788b67 commit c05049d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions spec/compiler/lexer/lexer_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
Expand Down
7 changes: 7 additions & 0 deletions src/compiler/crystal/syntax/lexer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c05049d

Please sign in to comment.