Skip to content

Commit 68a49e0

Browse files
committed
tryparse should still throw an exception on invalid base
1 parent 0d1cee7 commit 68a49e0

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

base/gmp.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ function tryparse_internal(::Type{BigInt}, s::AbstractString, startpos::Int, end
8484

8585
sgn, base, i = Base.parseint_preamble(true,base,bstr,start(bstr),endof(bstr))
8686
if !(2 <= base <= 62)
87-
raise && throw(ArgumentError("invalid base: base must be 2 ≤ base ≤ 62, got $base"))
88-
return _n
87+
throw(ArgumentError("invalid base: base must be 2 ≤ base ≤ 62, got $base"))
8988
end
9089
if i == 0
9190
raise && throw(ArgumentError("premature end of integer: $(repr(bstr))"))

base/parse.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ function tryparse_internal{T<:Integer}(::Type{T}, s::AbstractString, startpos::I
6363
_n = Nullable{T}()
6464
sgn, base, i = parseint_preamble(T<:Signed, base, s, startpos, endpos)
6565
if !(2 <= base <= 62)
66-
raise && throw(ArgumentError("invalid base: base must be 2 ≤ base ≤ 62, got $base"))
67-
return _n
66+
throw(ArgumentError("invalid base: base must be 2 ≤ base ≤ 62, got $base"))
6867
end
6968
if i == 0
7069
raise && throw(ArgumentError("premature end of integer: $(repr(SubString(s,startpos,endpos)))"))

test/parse.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,5 +538,9 @@ end
538538
@test_throws ArgumentError parse(Int, "2", 1)
539539
@test_throws ArgumentError parse(Int, "2", 63)
540540

541+
# tryparse should still throw on invalid base
542+
@test_throws ArgumentError tryparse(Int32, "0", 1)
543+
@test_throws ArgumentError tryparse(BigInt, "0", 1)
544+
541545
# error throwing branch from #10560
542546
@test_throws ArgumentError Base.tryparse_internal(Bool, "foo", 1, 2, 10, true)

0 commit comments

Comments
 (0)