JuliaLang / JuliaLang/JuliaSyntax.jl
Better diagnostic for block-like `begin ... end` in `typed_hcat`
- Dominant language
- Julia
- Stars
- 293
- Forks
- 50
- PR merge metrics
- No merged PRs in 30d
Description
Over at https://github.com/JuliaLang/julia/issues/46364 @eschnett observed
> The array expression `[begin 1 end]` creates a 1-element array. The `begin`...`end` block is not really necessary here, but can be convenient if the expression is much more complicated, e.g. a comprehension.
>
> The typed array expression `Int[begin 1 end]` leads to the parsing error `ERROR: syntax: unexpected "end"`.
This being due to the ambiguity of whether `begin` or `end` in the first slot inside `a[]` should be treated as block keywords or as the first/last indices of the array:
```julia
julia> dump(:(a[end 1]))
Expr
head: Symbol typed_hcat
args: Array{Any}((3,))
1: Symbol a
2: Symbol end
3: Int64 1
julia> dump(:(a[1 end]))
ERROR: syntax: unexpected "end"
Stacktrace:
[1] top-level scope
@ none:1
```
Over in that issue, it was suggested that the parser could explain the issue and suggest using `let` instead of `begin`, which seems like a good option.
See also: https://github.com/JuliaLang/JuliaSyntax.jl/pull/81
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.