# A bug in ASTInterpreter2?

**URL:** <https://discourse.julialang.org/t/a-bug-in-astinterpreter2/6391>\
**Category:** General Usage\
**Created:** [October 11, 2017, 3:20pm UTC](https://discourse.julialang.org/t/a-bug-in-astinterpreter2/6391 "2017-10-11T15:20:06Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [October 11, 2017, 3:20pm UTC](https://discourse.julialang.org/t/a-bug-in-astinterpreter2/6391/1 "2017-10-11T15:20:06Z")

</div>

Here is a MWE:

```julia
macro add(num)
    addnum = parse("add"*string(num))
    return esc(quote
        $num(x...) = $addnum(x...)
    end)
end

@add(one)
@add(two)

function addone(k::Integer)
  k = k + 1
  return k
end

function addtwo(k::Integer)
  k = k + 2
  return k
end

```

I expected to be able to step into function `addone`. But, it was totally skipped.

```julia
julia> @enter one(2)
In one(x) at /home/chobbes/code/test_macro.jl:4
4 $num(x...) = $addnum(x...)
5 end)
6 end

About to run: (Core._apply)(addone, (2,))
1|debug > s
In one(x) at /home/chobbes/code/test_macro.jl:4
4 $num(x...) = $addnum(x...)
5 end)
6 end

About to run: return 3
1|debug > 

julia> 

```

If the splatting `...` is removed in the above code, the ASTInterpreter then would step in the function.

---

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [October 11, 2017, 3:24pm UTC](https://discourse.julialang.org/t/a-bug-in-astinterpreter2/6391/2 "2017-10-11T15:24:35Z")

</div>

This problem wasn’t seen with v5.0 + ASTInterpreter.

---

<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:** [October 11, 2017, 4:01pm UTC](https://discourse.julialang.org/t/a-bug-in-astinterpreter2/6391/3 "2017-10-11T16:01:15Z")

</div>

What happens if you run julia as `julia --inline=no`?

---

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [October 11, 2017, 6:14pm UTC](https://discourse.julialang.org/t/a-bug-in-astinterpreter2/6391/4 "2017-10-11T18:14:22Z")

</div>

> [@kristoffer.carlsson](#):
>
> What happens if you run julia as julia --inline=no?

Tried. No difference.

---

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [October 12, 2017, 3:06pm UTC](https://discourse.julialang.org/t/a-bug-in-astinterpreter2/6391/5 "2017-10-12T15:06:26Z")

</div>

Today I found even more cases where ASTInterpreter2 fails to step in a function. I wish I could have time to work out a MWE for each case. Any fix (or botch) is much appreciated!

---

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [October 12, 2017, 10:59pm UTC](https://discourse.julialang.org/t/a-bug-in-astinterpreter2/6391/6 "2017-10-12T22:59:59Z")

</div>

Just did some more experiments - 90% of the erroneous skippings of step-in are caused by misinterpretation of splatting `...`.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 13, 2017, 6:23am UTC](https://discourse.julialang.org/t/a-bug-in-astinterpreter2/6391/7 "2017-10-13T06:23:00Z")

</div>

You are much more likely to get it fixed sooner if you make an effort to produce a MWE and open an issue.

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [October 21, 2017, 9:07pm UTC](https://discourse.julialang.org/t/a-bug-in-astinterpreter2/6391/8 "2017-10-21T21:07:26Z")

</div>

This is fixed now: [https://github.com/Keno/ASTInterpreter2.jl/commit/72b96acba8c9ccb1a52ef7f43e5c62bcd2fc3916](https://github.com/Keno/ASTInterpreter2.jl/commit/72b96acba8c9ccb1a52ef7f43e5c62bcd2fc3916)

but @Tamas_Papp is right, issues are better, because that way I won’t forget.

---

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [October 21, 2017, 9:35pm UTC](https://discourse.julialang.org/t/a-bug-in-astinterpreter2/6391/9 "2017-10-21T21:35:04Z")

</div>

Thanks a lot, @Keno. I wasn’t 100% sure if it is a bug. An issue can’t be deleted on Github. Don’t want to contaminate the repo by a false issue in case I misjudge.

---

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [November 9, 2017, 3:02pm UTC](https://discourse.julialang.org/t/a-bug-in-astinterpreter2/6391/10 "2017-11-09T15:02:49Z")

</div>

After checking out the commits pushed to ASTInterpret2 and DebuggerFramework in the last few days, debugger ceased to work. Macro `@enter` throws an error message:

```julia
ERROR: UndefVarError: __module__ not defined

```

Am I missing something? Thanks!

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [November 9, 2017, 3:03pm UTC](https://discourse.julialang.org/t/a-bug-in-astinterpreter2/6391/11 "2017-11-09T15:03:44Z")

</div>

No, I broke something. Please use the tagged version for your day to day needs.

---

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [November 9, 2017, 3:21pm UTC](https://discourse.julialang.org/t/a-bug-in-astinterpreter2/6391/12 "2017-11-09T15:21:39Z")

</div>

Thanks, @Keno.

---

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [November 24, 2017, 11:54pm UTC](https://discourse.julialang.org/t/a-bug-in-astinterpreter2/6391/13 "2017-11-24T23:54:25Z")

</div>

@Keno ASTInterpreter2 looks problematic with slurping too, like splatting, though I’m not 100% sure. Here is an MWE:

```julia
function add(a,b;AddOneMore::Int=0)
  s = a+b
  if AddOneMore ≠ 0
    s += 1
  end
  return s
end

plus(a,b;kwds...) = add(a,b;kwds...)

```

When I try to @enter `plus`, I’m bounced:

```julia
@enter plus(1,2;AddOneMore=1)
ERROR: UndefRefError: access to undefined reference
Stacktrace:
 [1] lookup_var(::ASTInterpreter2.JuliaStackFrame, ::SSAValue) at /home/chobbes/Documents/git/ASTInterpreter2.jl/src/interpret.jl:3
 [2] evaluate_call(::ASTInterpreter2.JuliaStackFrame, ::Expr) at /home/chobbes/Documents/git/ASTInterpreter2.jl/src/interpret.jl:32
 [3] _step_expr(::ASTInterpreter2.JuliaStackFrame, ::ASTInterpreter2.JuliaProgramCounter) at /home/chobbes/Documents/git/ASTInterpreter2.jl/src/interpret.jl:87
 [4] next_until!(::ASTInterpreter2.##7#8, ::ASTInterpreter2.JuliaStackFrame, ::ASTInterpreter2.JuliaProgramCounter) at /home/chobbes/Documents/git/ASTInterpreter2.jl/src/interpret.jl:144
 [5] maybe_step_through_wrapper!(::Array{ASTInterpreter2.JuliaStackFrame,1}) at /home/chobbes/Documents/git/ASTInterpreter2.jl/src/ASTInterpreter2.jl:429

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 25, 2017, 6:12am UTC](https://discourse.julialang.org/t/a-bug-in-astinterpreter2/6391/14 "2017-11-25T06:12:47Z")

</div>

> [@chobbes](#):
>
> Here is an MWE

If you open issues [on Github](https://github.com/Keno/ASTInterpreter2.jl/issues), they are less likely to get lost and you make them easier to manager for the author.
