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 does not work #71

Open
Wynand opened this issue Aug 9, 2022 · 2 comments
Open

tryparse does not work #71

Wynand opened this issue Aug 9, 2022 · 2 comments

Comments

@Wynand
Copy link

Wynand commented Aug 9, 2022

Code to test, using Julia 1.6.6 and FixedPointDecimals 0.4.0:

julia> using FixedPointDecimals

julia> tryparse(FixedDecimal{Int64,2},"1.5")
ERROR: MethodError: no method matching tryparse(::Type{FixedDecimal{Int64, 2}}, ::String)
Closest candidates are:
  tryparse(::Type{Complex{S}}, ::AbstractString) where S<:Real at parse.jl:384
  tryparse(::Type{T}, ::AbstractString) where T<:Dates.TimeType at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/Dates/src/parse.jl:288
  tryparse(::Type{T}, ::AbstractString, ::Dates.DateFormat) where T<:Dates.TimeType at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/Dates/src/parse.jl:288
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[2]:1

julia>

It might be useful to look at the base implementation of parse to fix this

@Wynand
Copy link
Author

Wynand commented Aug 9, 2022

A naive fix might be to implement something like this:

function Base.tryparse(::Type{FD}, args...; kwargs...) where FD <: FixedDecimal
    try
        return parse(FD,args...;kwargs...)
    catch
        return nothing
    end
end

@Drvi
Copy link
Collaborator

Drvi commented Jun 20, 2023

Fixed by #80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants