Skip to content

Commit 32b77ac

Browse files
committed
epxanded comment on BangBang hack
1 parent 6a21ee2 commit 32b77ac

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/utils.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,17 @@ function BangBang.possible(
514514
return BangBang.implements(setindex!, C) &&
515515
promote_type(eltype(C), eltype(T)) <: eltype(C)
516516
end
517-
# NOTE: Makes it possible to use ranges, etc. for setting a vector.
517+
# HACK: Makes it possible to use ranges, etc. for setting a vector.
518+
# For example, without this hack, BangBang.jl will consider
519+
#
520+
# x[1:2] = [1, 2]
521+
#
522+
# as NOT supported. This results is calling the immutable
523+
# `BangBang.setindex` instead, which also ends up expanding the
524+
# type of the containing array (`x` in the above scenario) to
525+
# have element type `Any`.
526+
# The below code just, correctly, marks this as possible and
527+
# thus we hit the mutable `setindex!` instead.
518528
function BangBang.possible(
519529
::typeof(BangBang._setindex!), ::C, ::T, ::AbstractVector{<:Integer}
520530
) where {C<:AbstractVector,T<:AbstractVector}

0 commit comments

Comments
 (0)