String7 and Bools : bug or feature?

This one got me (by reading in a DataFrame via CSV).

Is this behavior intentional?


julia> using CSV

julia> x = String7( "4" )
"4"

julia> parse( Int, x )
4

julia> y = String7( "true" )
"true"

julia> parse( Bool, y )
ERROR: InexactError: Bool(10)
Stacktrace:
 [1] Bool
   @ ./float.jl:158 [inlined]
 [2] convert
   @ ./number.jl:7 [inlined]
 [3] tryparse_internal(#unused#::Type{Bool}, s::String7, startpos::Int64, endpos::Int64, base_::Int64, raise::Bool)
   @ Base ./parse.jl:126
 [4] parse(::Type{Bool}, s::String7; base::Nothing)
   @ Base ./parse.jl:241
 [5] parse(::Type{Bool}, s::String7)
   @ Base ./parse.jl:240
 [6] top-level scope
   @ REPL[5]:1

julia> z = String( y )
"true"

julia> parse( Bool, z )
true

String7 belongs to the InlineStrings package. I guess this is an InlineStrings bug, however, it’s fixed in the latest version, v1.4.0, of InlineStrings.

What’s your version of InlineStrings? Try updating and see if it fixes the bug.

It doesn’t appear to be fixed in v1.4.0.

I can confirm the error for InlineStrings 1.4.0. Incidentally, my related package StaticStrings.jl also has the same issue.

julia> parse(Bool, inline"true")
ERROR: InexactError: Bool(10)
Stacktrace:
 [1] Bool
   @ ./float.jl:171 [inlined]
 [2] convert
   @ ./number.jl:7 [inlined]
 [3] tryparse_internal(#unused#::Type{Bool}, s::String7, startpos::Int64, endpos::Int64, base_::Int64, raise::Bool)
   @ Base ./parse.jl:126
 [4] parse(::Type{Bool}, s::String7; base::Nothing)
   @ Base ./parse.jl:241
 [5] parse(::Type{Bool}, s::String7)
   @ Base ./parse.jl:240
 [6] top-level scope
   @ REPL[33]:1

julia> parse(Bool, inline"true"; base=2)
ERROR: InexactError: Bool(2)
Stacktrace:
 [1] Bool
   @ ./float.jl:171 [inlined]
 [2] convert
   @ ./number.jl:7 [inlined]
 [3] tryparse_internal(#unused#::Type{Bool}, s::String7, startpos::Int64, endpos::Int64, base_::Int64, raise::Bool)
   @ Base ./parse.jl:126
 [4] parse(::Type{Bool}, s::String7; base::Int64)
   @ Base ./parse.jl:241
 [5] top-level scope
   @ REPL[34]:1

julia> using StaticStrings

julia> parse(Bool, static"true"; base=2)
ERROR: InexactError: Bool(2)
Stacktrace:
 [1] Bool
   @ ./float.jl:171 [inlined]
 [2] convert
   @ ./number.jl:7 [inlined]
 [3] tryparse_internal(#unused#::Type{Bool}, s::StaticString{4}, startpos::Int64, endpos::Int64, base_::Int64, raise::Bool)
   @ Base ./parse.jl:126
 [4] parse(::Type{Bool}, s::StaticString{4}; base::Int64)
   @ Base ./parse.jl:241
 [5] top-level scope
   @ ~/.julia/packages/StaticStrings/oSXOl/src/macros.jl:19

The problem appears to be related to the base.

Meta.parse seems to work just fine though.

julia> Meta.parse(static"true")
true

julia> Meta.parse(inline"true")
true

Sorry, this was a Julia Base bug, it has been fixed seven months ago, but I guess the fix wasn’t backported to any releases:

parse certainly works for me on nightly Julia.

This should be fixed in 1.6.8, 1.8.5, 1.9.3, and 1.10.0 (none of which have been released atm)

[Edit: corrected]

Actually, v1.9.2 was released two days ago. I think you mean v1.9.3, because v1.9.2 still seems to be buggy.