# Assigning values of different types to unused variable

**URL:** <https://discourse.julialang.org/t/assigning-values-of-different-types-to-unused-variable/912>\
**Category:** General Usage\
**Created:** [December 13, 2016, 8:27am UTC](https://discourse.julialang.org/t/assigning-values-of-different-types-to-unused-variable/912 "2016-12-13T08:27:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 13, 2016, 8:27am UTC](https://discourse.julialang.org/t/assigning-values-of-different-types-to-unused-variable/912/1 "2016-12-13T08:27:27Z")

</div>

Sometimes it is convenient to use `_` as a placehold for return values you do not care about. I wonder if there is any “danger” in something similar to:

```nohighlight
f() = 1.0, 1, "foo"

function g()
    a, _, _ = f()
end

```

Here the variable `_` is assigned to twice with different types so it is not type stable. Will this be a performance problem even if I never use `_` later in the function?

---

<div class="post-metadata">

**Author:** ![bicycle1885](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bicycle1885/32/107_2.png) [@bicycle1885](https://discourse.julialang.org/u/bicycle1885)\
**Post date:** [December 13, 2016, 8:54am UTC](https://discourse.julialang.org/t/assigning-values-of-different-types-to-unused-variable/912/2 "2016-12-13T08:54:14Z")

</div>

Unused variables will be optimized out in this case, but I’m not sure whether this always happens. Checking `@code_llvm` would be helpful.

```julia
julia> function g()
           a, _, _ = f()
           return a + 1
       end
g (generic function with 1 method)

julia> g()
2.0

julia> @code_llvm g()

define double @julia_g_70869() #0 {
top:
  %0 = load double, double* inttoptr (i64 4584977520 to double*), align 16
  %1 = fadd double %0, 1.000000e+00
  ret double %1
}

```

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [December 13, 2016, 1:06pm UTC](https://discourse.julialang.org/t/assigning-values-of-different-types-to-unused-variable/912/3 "2016-12-13T13:06:32Z")

</div>

Please use `code_warntype` instead of these.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 13, 2016, 1:54pm UTC](https://discourse.julialang.org/t/assigning-values-of-different-types-to-unused-variable/912/4 "2016-12-13T13:54:01Z")

</div>

`@code_warntype` will show the type instability but not if it is a performance problem during run time?

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [December 13, 2016, 4:42pm UTC](https://discourse.julialang.org/t/assigning-values-of-different-types-to-unused-variable/912/5 "2016-12-13T16:42:09Z")

</div>

I think the point of showing LLVM code is that the ignored variable is clearly completely eliminated in this case, which makes sense to me. Even if `@code_warntype` is really unhappy about the inferred types, if the LLVM code is fine it won’t affect performance.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 13, 2016, 4:43pm UTC](https://discourse.julialang.org/t/assigning-values-of-different-types-to-unused-variable/912/6 "2016-12-13T16:43:25Z")

</div>

The analysis in [https://github.com/JuliaLang/julia/pull/15558#issuecomment-265533514](https://github.com/JuliaLang/julia/pull/15558#issuecomment-265533514) seems to indicate that it can sometimes be a problem.
