Skip to content

Invalid code displayed for block in if statement #56198

Open

Description

I am using quoting to generate Julia code. The following is legal Julia code (that is executed correctly), but its display output is not legal Julia code.

julia> cond = quote
           dish = 4
           dish < 5
       end

julia> :($cond ? 10 : 20)
:(if #= REPL[23]:2 =#, dish = 4, #= REPL[23]:3 =#, dish < 5
      10
  else
      20
  end)

The condition cond is output separated by commas, as if it was a tuple, but it should probably be output enclosed in a begin ... end block, separated by semicolons.

This is the internal representation. It looks correct:

julia> :($cond ? 10 : 20) |> dump
Expr
  head: Symbol if
  args: Array{Any}((3,))
    1: Expr
      head: Symbol block
      args: Array{Any}((4,))
        1: LineNumberNode
          line: Int64 2
          file: Symbol REPL[23]
        2: Expr
          head: Symbol =
          args: Array{Any}((2,))
            1: Symbol dish
            2: Int64 4
        3: LineNumberNode
          line: Int64 3
          file: Symbol REPL[23]
        4: Expr
          head: Symbol call
          args: Array{Any}((3,))
            1: Symbol <
            2: Symbol dish
            3: Int64 5
    2: Int64 10
    3: Int64 20

I am using Julia 1.11.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviordisplay and printingAesthetics and correctness of printed representations of objects.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions