# Strange white space dependence with @assert

**URL:** <https://discourse.julialang.org/t/strange-white-space-dependence-with-assert/59825>\
**Category:** General Usage\
**Created:** [April 22, 2021, 8:05pm UTC](https://discourse.julialang.org/t/strange-white-space-dependence-with-assert/59825 "2021-04-22T20:05:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [April 22, 2021, 8:05pm UTC](https://discourse.julialang.org/t/strange-white-space-dependence-with-assert/59825/1 "2021-04-22T20:05:10Z")

</div>

Julia syntax is usually insensitive to white space, but I encountered a situation when `@assert` introduces a strange dependence on white space. Is this a bug? (I’m using Julia 1.6.0.)

```
julia> t = Int64[1,2];

julia> @assert t[1]+1 == t[2]

julia> @assert t[1] +1 == t[2]
ERROR: TypeError: non-boolean (Int64) used in boolean context
Stacktrace:
 [1] top-level scope
   @ REPL[3]:1

julia> t[1]+1 == t[2]
true

julia> t[1] +1 == t[2]
true

```

---

<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:** [April 22, 2021, 8:54pm UTC](https://discourse.julialang.org/t/strange-white-space-dependence-with-assert/59825/2 "2021-04-22T20:54:27Z")

</div>

```julia
julia> @macroexpand( @assert t[1]+1 == t[2] )
:(if t[1] + 1 == t[2]
      nothing
  else
      Base.throw(Base.AssertionError("t[1] + 1 == t[2]"))
  end)

julia> @macroexpand( @assert t[1] +1 == t[2] )
:(if t[1]
      nothing
  else
      Base.throw(Base.AssertionError((Base.Main).Base.string(1 == t[2])))
  end)

```

I would say it’s a bug.  
But you can avoid it by using parantheses:

```julia
julia> @macroexpand( @assert( t[1] +1 == t[2] ) )
:(if t[1] + 1 == t[2]
      nothing
  else
      Base.throw(Base.AssertionError("t[1] + 1 == t[2]"))
  end)

```

---

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [April 22, 2021, 9:24pm UTC](https://discourse.julialang.org/t/strange-white-space-dependence-with-assert/59825/3 "2021-04-22T21:24:15Z")

</div>

I think it’s a quirk of macro parsing, that because the part after the space is a valid expression, it gets treated as a second argument:

```julia
julia> @show t[1]+1 == t[2];
t[1] + 1 == t[2] = true

julia> @show t[1] +1 == t[2];
t[1] = 1
1 == t[2] = false

julia> @show t[1] *1 == t[2]; # * cannot be a unary operator
t[1] * 1 == t[2] = false

```

The same is true inside matrix-building syntax:

```julia
julia> [t[1]+1]
1-element Vector{Int64}:
 2

julia> [t[1] +1]
1×2 Matrix{Int64}:
 1 1

julia> [t[1] + 1] # symmetric space
1-element Vector{Int64}:
 2

```
