# Odd syntax error with type parameter and array literal

**URL:** <https://discourse.julialang.org/t/odd-syntax-error-with-type-parameter-and-array-literal/51164>\
**Category:** General Usage\
**Tags:** question, syntax, parsing\
**Created:** [December 3, 2020, 2:33am UTC](https://discourse.julialang.org/t/odd-syntax-error-with-type-parameter-and-array-literal/51164 "2020-12-03T02:33:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hexane](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hexane/32/19927_2.png) [@hexane](https://discourse.julialang.org/u/hexane)\
**Post date:** [December 3, 2020, 2:33am UTC](https://discourse.julialang.org/t/odd-syntax-error-with-type-parameter-and-array-literal/51164/1 "2020-12-03T02:33:22Z")

</div>

I recently ran into a weird parsing error with Julia when defining the following function:

```julia
julia> function to_array(val::T)::Array{T} where {T} [val] end
ERROR: syntax: space before "[" not allowed in "{T} [" at REPL[14]:1
Stacktrace:
 [1] top-level scope at none:1

```

If I add a newline before the function body, it parses and runs fine.

If I remove the type parameter, I get the same syntax error but with the return type:

```julia
julia> function to_arr(val::T)::Array{T} [val] end
ERROR: syntax: space before "[" not allowed in "Array{T} [" at REPL[27]:1
Stacktrace:
 [1] top-level scope at none:1

```

Does anybody have any idea why this happens? I don’t know of any language feature that allows square brackets in this position. I guess some parsing step is failing and the parser doesn’t know to backtrack and attempt to parse the block, but I don’t really know anything about how the parser works so I can’t really speculate.

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [December 3, 2020, 3:02am UTC](https://discourse.julialang.org/t/odd-syntax-error-with-type-parameter-and-array-literal/51164/2 "2020-12-03T03:02:13Z")

</div>

That’s looks like a bug.  
Open an issue at [Issues · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues)
