Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/parse_stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -865,20 +865,26 @@ function validate_literal_tokens(stream::ParseStream)
# parse_int_literal
# parse_uint_literal
elseif k == K"Float" || k == K"Float32"
underflow0 = false
if k == K"Float"
_, code = parse_float_literal(Float64, text, fbyte, nbyte)
x, code = parse_float_literal(Float64, text, fbyte, nbyte)
# jl_strtod_c can return "underflow" even for valid cases such
# as `5e-324` where the source is an exact representation of
# `x`. So only warn when underflowing to zero.
underflow0 = code == :underflow && x == 0
else
_, code = parse_float_literal(Float32, text, fbyte, nbyte)
x, code = parse_float_literal(Float32, text, fbyte, nbyte)
underflow0 = code == :underflow && x == 0
end
if code == :ok
# pass
elseif code == :overflow
emit_diagnostic(stream, fbyte, lbyte,
error="overflow in floating point literal")
had_error = true
elseif code == :underflow
elseif underflow0
emit_diagnostic(stream, fbyte, lbyte,
warning="underflow in floating point literal")
warning="underflow to zero in floating point literal")
end
elseif k == K"Char"
@assert fbyte < nbyte # Already handled in the parser
Expand Down
8 changes: 6 additions & 2 deletions test/diagnostics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ end
@test diagnostic("x = 10.0f1000;") ==
Diagnostic(5, 13, :error, "overflow in floating point literal")
@test diagnostic("x = 10.0e-1000;") ==
Diagnostic(5, 14, :warning, "underflow in floating point literal")
Diagnostic(5, 14, :warning, "underflow to zero in floating point literal")
@test diagnostic("x = 10.0f-1000;") ==
Diagnostic(5, 14, :warning, "underflow in floating point literal")
Diagnostic(5, 14, :warning, "underflow to zero in floating point literal")
# Underflow boundary
@test diagnostic("5e-324", allow_multiple=true) == []
@test diagnostic("2e-324") ==
Diagnostic(1, 6, :warning, "underflow to zero in floating point literal")

# Char
@test diagnostic("x = ''") ==
Expand Down