# Weird errors in Juno

**URL:** https://discourse.julialang.org/t/weird-errors-in-juno/33379
**Category:** Juno
**Created:** [January 15, 2020, 6:02am UTC](https://discourse.julialang.org/t/weird-errors-in-juno/33379 "2020-01-15T06:02:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![nxtruong](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nxtruong/32/7991_2.png) [@nxtruong](https://discourse.julialang.org/u/nxtruong)
#### Post date: [January 15, 2020, 6:02am UTC](https://discourse.julialang.org/t/weird-errors-in-juno/33379/1 "2020-01-15T06:02:39Z")

</div>

I’m using the current version of Juno (uber-juno 0.3.0) on Atom 1.42.0, with Julia 1.3.0 (Julia 1.3.1 has the same issues, just slightly different error messages). I’ve been seeing weird errors that **only happen in Juno** , **not in Julia command line (from the terminal, outside of Juno)**.

Consider the following code:

```julia
mutable struct AS
    a
    b
    AS() = new(1.0)
end
function set_states!(c::AS, b::Number)
    c.b = b
end

AAS = [AS() for _ in 1:5]

```

Running it in Juno is fine, returning:

```julia
2-element Array{AS,1}:
 AS(1.0, #undef)
 AS(1.0, #undef)

```

Then run the following code:

```julia
for k in 1:2
    set_states!(AAS[k], 0.)
end

```

It will basically crash Julia in Juno with the error (text is long, so I only include the first few lines):

```julia
Error showing value of type Array{AS,1}:
ERROR: StackOverflowError:
Stacktrace:
 [1] _show_default(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::Any) at ./show.jl:334
 [2] show_default at ./show.jl:330 [inlined]
 [3] show(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::Any) at ./show.jl:327
 ... (the last 3 lines are repeated 26170 more times)

```

What could be wrong?

---

<div class="post-metadata">

### Author: ![nxtruong](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nxtruong/32/7991_2.png) [@nxtruong](https://discourse.julialang.org/u/nxtruong)
#### Post date: [January 15, 2020, 6:10am UTC](https://discourse.julialang.org/t/weird-errors-in-juno/33379/2 "2020-01-15T06:10:04Z")

</div>

A different but still weird error for similar code (just changed slightly from the above).

Run the following code in Juno (paste in a file, select, then run the code):

```julia
mutable struct AS
    a
    b
    AS() = new(1.0, 2.0)
end
function set_states!(c::AS, b::Number)
    c.b = b
end

AAS = [AS() for _ in 1:2]

```

As you can see, it’s changed only slightly from the previous. It returns as expected

```julia
2-element Array{AS,1}:
 AS(1.0, 2.0)
 AS(1.0, 2.0)

```

Then run the following code in Juno (paste, select, run):

```julia
for k in 1:2
    set_states!(AAS[k], 0.)
end

```

Then type `AAS[1]` in the REPL in Juno and get:

```julia
AS(1.0, (Core.Compiler.UseRef(:(Core.bitcast(Core.UInt, %96)), 4), nothing))

```

It should have shown `AS(1.0, 0.0)` instead.

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [January 15, 2020, 9:32am UTC](https://discourse.julialang.org/t/weird-errors-in-juno/33379/3 "2020-01-15T09:32:52Z")

</div>

I don’t know exactly why but the error does not happen if you set the type of the struct members:

```julia
mutable struct AS
    a::Float64
    b::Float64
    AS() = new(1.0, 2.0)
end

```

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [January 15, 2020, 12:23pm UTC](https://discourse.julialang.org/t/weird-errors-in-juno/33379/4 "2020-01-15T12:23:53Z")

</div>

```julia
julia> begin
       mutable struct AS
           a
           b
           AS() = new(1.0)
       end
       function set_states!(c::AS, b::Number)
           c.b = b
       end

       AAS = [AS() for _ in 1:2]
       end;

julia> for k in 1:2
           @show AAS[k]
           @show set_states!(AAS[k], 9.91)
           @show AAS[k]
       end
AAS[k] = AS(1.0, #undef)
set_states!(AAS[k], 9.91) = 9.91
AAS[k] = AS(1.0, 9.91)
AAS[k] = AS(1.0, #undef)
set_states!(AAS[k], 9.91) = 9.91
AAS[k] = AS(1.0, 9.91)

julia> @show AAS[1];
AAS[1] = AS(1.0, 9.91)

julia> AAS
2-element Array{AS,1}:
 AS(1.0, :(%1090))
 AS(1.0, :(%1090))

julia> AAS
2-element Array{AS,1}:
Error showing value of type Array{AS,1}:

```

I suspect this happens because Juno is holding on to `AAS` in a bunch of nested closures and then _something_ bad happens and we’re back to the original, unset value interpreted as a pointer to random memory or whatever.  
No idea why this is happening though, I’m fairly certain Juno never does any modifications to displayed objects like that.
