JuliaFolds / BangBang.jl

Immutables as mutables, mutables as immutables.
MIT License
107 stars 11 forks source link

Type "instability" in `_setindex` with slices #233

Open phipsgabler opened 2 years ago

phipsgabler commented 2 years ago

I was trying to find a fix for https://github.com/jw3126/Setfield.jl/issues/175, a bug in Setfields's type stability, and took a look at what NoBang is doing; turns out it uses the same code, and suffers from the same issue:

julia> _setindex(rand(2,2), Float64[100, 100], 1, :)
2×2 Matrix{Any}:
 100.0       100.0
   0.309041    0.986011

The problem is that the typeof(v) is wrong when the RHS is an iterable written to a slice.

I don't yet know of a better fix. eltype(v) does not generalize beyond number-like types.

phipsgabler commented 2 years ago

(Is it even right to call this an instability? Probably it's rather a promotion gone wrong, and then stable with a too general type.)