Skip to content

Better diagnostic for block-like begin ... end in typed_hcat #92

Open
@c42f

Description

@c42f

Over at JuliaLang/julia#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> 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: #81

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesterror messagesBetter, more actionable diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions