# \`@inbounds\` behaving strangely for varargs functions

**URL:** <https://discourse.julialang.org/t/inbounds-behaving-strangely-for-varargs-functions/85752>\
**Category:** General Usage\
**Created:** [August 15, 2022, 1:58am UTC](https://discourse.julialang.org/t/inbounds-behaving-strangely-for-varargs-functions/85752 "2022-08-15T01:58:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthias314](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Post date:** [August 15, 2022, 1:58am UTC](https://discourse.julialang.org/t/inbounds-behaving-strangely-for-varargs-functions/85752/1 "2022-08-15T01:58:50Z")

</div>

I am puzzled by the behavior of `@inbounds` for functions with a variable number of arguments. My understanding is that calling the following function `g` should avoid a bounds check inside `f`.

```julia
@inline function f(x...)
    @boundscheck println("checking bounds")
    return 0
end

g(x...) = @inbounds f(x...)

```

However, this is what I get:

```julia
julia> g(1) # OK
0
julia> g(1,1) # why is this?
checking bounds
0
julia> g(1) # and why does this suddenly change?
checking bounds
0

```

I’m using Julia 1.7.3.

---

<div class="post-metadata">

**Author:** ![ikirill](https://avatars.discourse-cdn.com/v4/letter/i/43a26b/32.png) [@ikirill](https://discourse.julialang.org/u/ikirill)\
**Post date:** [August 15, 2022, 6:32am UTC](https://discourse.julialang.org/t/inbounds-behaving-strangely-for-varargs-functions/85752/2 "2022-08-15T06:32:10Z")

</div>

When I examine `g(1,1)` with `@descend`, it actually removes the bounds check correctly.

When I run `Debugger.@run g(1)`, it prints `checking bounds` even the first time round. Huh.

Maybe it’s because `f(x...)` is actually `Core._apply_iterate(Base.iterate, Main.f, x)`, and that call doesn’t propagate inbounds?

---

<div class="post-metadata">

**Author:** ![matthias314](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Post date:** [August 15, 2022, 3:10pm UTC](https://discourse.julialang.org/t/inbounds-behaving-strangely-for-varargs-functions/85752/3 "2022-08-15T15:10:25Z")

</div>

> [@ikirill](#):
>
> Maybe it’s because `f(x...)` is actually `Core._apply_iterate(Base.iterate, Main.f, x)`, and that call doesn’t propagate inbounds?

If that’s true, then why is the bounds check skipped when calling `g(1)` the first time?

I’ve just tried again, and sometimes I don’t see a change in the behavior for `g(1)`, but most times I do. `g(1,1)` always gives a bounds check.

`@code_typed` and `@code_llvm` also claim that there is no bounds check, neither for `g(1)` nor for `g(1,1)`.

---

<div class="post-metadata">

**Author:** ![matthias314](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Post date:** [August 17, 2022, 12:15pm UTC](https://discourse.julialang.org/t/inbounds-behaving-strangely-for-varargs-functions/85752/4 "2022-08-17T12:15:52Z")

</div>

There is now a [GitHub issue](https://github.com/JuliaLang/julia/issues/46351) for this.
