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

convert(T<:StaticInt{8}, x) does not always return a T #96

Open
KristofferC opened this issue Jan 2, 2023 · 5 comments
Open

convert(T<:StaticInt{8}, x) does not always return a T #96

KristofferC opened this issue Jan 2, 2023 · 5 comments

Comments

@KristofferC
Copy link

julia> convert(Static.StaticInt{8}, 0)
ERROR: TypeError: in typeassert, expected StaticInt{8}, got a value of type StaticInt{0}

I've seen this error in e.g. PkgEval https://s3.amazonaws.com/julialang-reports/nanosoldier/pkgeval/by_hash/7daffee_vs_00177eb/Fenrir.primary.log.

Ends up erroring from https://github.com/JuliaLinearAlgebra/Octavian.jl/blob/430701e05a88176ba1cf313b22f3a5c687fbfd4b/src/Octavian.jl#L49. cc @chriselrod

Having convert(Type{T}, x) return a T is pretty fundamental in Julia.

@Tokazama
Copy link
Collaborator

Tokazama commented Jan 2, 2023

Doesn't seem like returning StaticInt{8}() would be proper here either. Maybe change this to only work for Type{StaticInt} (the UnionAll typing)?

@KristofferC
Copy link
Author

That would be consistent with convert at least.

@chriselrod
Copy link
Collaborator

function convert(::StaticInt{N}, x) where {N}
    # choose whether you want the check to
    # possibly be skippable in the future:
    # x == N || throw(ArgumentError("$x != $N, so can't convert to a static($N)"))
    @assert x == N "$x != $N, so can't convert to a static($N)"
    return StaticInt{N}()
end

Seems like a reasonable definition.
Maybe a better error than the typeassert?
Octavian should be fixed to not do that.

@KristofferC
Copy link
Author

Looks like this was with ⌃ [6fd5a793] + Octavian v0.3.15 so maybe fixed already?

@chriselrod
Copy link
Collaborator

Sorry, I didn't look at the stacktrace:

  [1] convert
    @ ./number.jl:7 [inlined]
  [2] oftype(x::Static.StaticInt{8}, y::Int64)
    @ Base ./essentials.jl:471
  [3] zero(x::Static.StaticInt{8})
    @ Base ./number.jl:308
  [4] unsigned(x::Static.StaticInt{8})
    @ Base ./int.jl:215
  [5] divrem_fast
    @ ~/.julia/packages/Octavian/tN2Zr/src/integerdivision.jl:9 [inlined]

I thought Octavian was calling convert directly, but unsigned should be fine.
zero also already seems to be overloaded, so it shouldn't be inadvertently calling convert in this way anymore.

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

3 participants