Skip to content

The relative precedence of :: and where is strangely context dependent #55159

@LilithHafner

Description

@LilithHafner

From conversation with @c42f, the relative precedence of :: and where is strangely context dependent:

julia> using JuliaSyntax

julia> parsestmt(SyntaxNode, "function f()::T where T 0 end")
line:col│ tree                                   │ file_name
   1:1  │[function]
   1:10 │  [where]
   1:10 │    [::-i]
   1:10 │      [call]
   1:10 │        f
   1:15 │      T
   1:23 │    T
   1:24 │  [block]
   1:25 │    0


julia> parsestmt(SyntaxNode, "f()::T where T = 0")
line:col│ tree                                   │ file_name
   1:1  │[=]
   1:1  │  [::-i]
   1:1  │    [call]
   1:1  │      f
   1:6  │    [where]
   1:6  │      T
   1:14 │      T
   1:18 │  0

This also reproduces on pre-JS versions, but is less unambiguously visible

julia> :(function f()::T where T 0 end)
:(function (f()::T) where T
      #= REPL[26]:1 =#
      #= REPL[26]:1 =#
      0
  end)

julia> :(f()::T where T = 0)
:(f()::(T where T) = begin
          #= REPL[27]:1 =#
          0
      end)

Metadata

Metadata

Assignees

No one assigned

    Labels

    parserLanguage parsing and surface syntax

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions