Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tryparse(Bool, " ") throws an error instead of returning nothing #42616

Closed
DilumAluthge opened this issue Oct 12, 2021 · 1 comment · Fixed by #42623
Closed

tryparse(Bool, " ") throws an error instead of returning nothing #42616

DilumAluthge opened this issue Oct 12, 2021 · 1 comment · Fixed by #42623
Labels
bug Indicates an unexpected problem or unintended behavior strings "Strings!"

Comments

@DilumAluthge
Copy link
Member

julia> tryparse(Int, "") === nothing
true

julia> tryparse(Int, " ") === nothing
true

julia> tryparse(Bool, "") === nothing
true

julia> tryparse(Bool, " ")
ERROR: BoundsError: attempt to access 1-codeunit String at index [2]
Stacktrace:
 [1] checkbounds
   @ ./strings/basic.jl:216 [inlined]
 [2] codeunit
   @ ./strings/string.jl:102 [inlined]
 [3] getindex
   @ ./strings/string.jl:223 [inlined]
 [4] tryparse_internal(#unused#::Type{Bool}, sbuff::String, startpos::Int64, endpos::Int64, base::Int64, raise::Bool)
   @ Base ./parse.jl:197
 [5] #tryparse#456
   @ ./parse.jl:237 [inlined]
 [6] tryparse(::Type{Bool}, s::String)
   @ Base ./parse.jl:237
 [7] top-level scope
   @ REPL[4]:1
@DilumAluthge DilumAluthge added bug Indicates an unexpected problem or unintended behavior strings "Strings!" parser Language parsing and surface syntax and removed parser Language parsing and surface syntax labels Oct 12, 2021
@barucden
Copy link
Contributor

Similarly:

julia> parse(Bool, "") # ArgumentError as expected
ERROR: ArgumentError: input string is empty
Stacktrace:
 [1] tryparse_internal(#unused#::Type{Bool}, sbuff::String, startpos::Int64, endpos::Int64, base::Int64, raise::Bool)
   @ Base ./parse.jl:182
 [2] parse(::Type{Bool}, s::String; base::Nothing)
   @ Base ./parse.jl:241
 [3] parse(::Type{Bool}, s::String)
   @ Base ./parse.jl:241
 [4] top-level scope
   @ REPL[5]:1

julia> parse(Bool, " ") # BoundsError
ERROR: BoundsError: attempt to access 1-codeunit String at index [2]
Stacktrace:
 [1] checkbounds
   @ ./strings/basic.jl:216 [inlined]
 [2] codeunit
   @ ./strings/string.jl:102 [inlined]
 [3] getindex
   @ ./strings/string.jl:223 [inlined]
 [4] tryparse_internal(#unused#::Type{Bool}, sbuff::String, startpos::Int64, endpos::Int64, base::Int64, raise::Bool)
   @ Base ./parse.jl:197
 [5] parse(::Type{Bool}, s::String; base::Nothing)
   @ Base ./parse.jl:241
 [6] parse(::Type{Bool}, s::String)
   @ Base ./parse.jl:241
 [7] top-level scope
   @ REPL[6]:1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior strings "Strings!"
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants