Skip to content

Operator precedence in documentation wrong or misleading #14959

@lukaszsamson

Description

@lukaszsamson

Elixir and Erlang/OTP versions

Erlang/OTP 27 [erts-15.2.7.3] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit]

Elixir 1.19.3 (compiled with Erlang/OTP 27)

Operating system

any

Current behavior

https://hexdocs.pm/elixir/1.19.3/operators.html lists :: as having lower precedence than =>, yet

Code.string_to_quoted!("%{a :: b => c}")
{:%{}, [line: 1],
 [
   {{:"::", [line: 1], [{:a, [line: 1], nil}, {:b, [line: 1], nil}]},
    {:c, [line: 1], nil}}
 ]}

Code.string_to_quoted!("%{a => b :: c}")
{:%{}, [line: 1],
 [
   {{:a, [line: 1], nil},
    {:"::", [line: 1], [{:b, [line: 1], nil}, {:c, [line: 1], nil}]}}
 ]}

proves that it has higher precedence

Similarly, other operators listed below => all have higher precedence

iex(16)> Code.string_to_quoted!("%{a | b => c}")
{:%{}, [line: 1],
 [
   {:|, [line: 1],
    [{:a, [line: 1], nil}, [{{:b, [line: 1], nil}, {:c, [line: 1], nil}}]]}
 ]}
iex(17)> Code.string_to_quoted!("%{a when b => c}")
{:%{}, [line: 1],
 [
   {{:when, [line: 1], [{:a, [line: 1], nil}, {:b, [line: 1], nil}]},
    {:c, [line: 1], nil}}
 ]}
iex(18)> Code.string_to_quoted!("%{a <- b => c}")
{:%{}, [line: 1],
 [
   {{:<-, [line: 1], [{:a, [line: 1], nil}, {:b, [line: 1], nil}]},
    {:c, [line: 1], nil}}
 ]}
iex(19)> Code.string_to_quoted!("%{a \\\\ b => c}")
{:%{}, [line: 1],
 [
   {{:\\, [line: 1], [{:a, [line: 1], nil}, {:b, [line: 1], nil}]},
    {:c, [line: 1], nil}}
 ]}

iex(23)> Code.string_to_quoted!("%{a => b | c}")
{:%{}, [line: 1],
 [
   {{:a, [line: 1], nil},
    {:|, [line: 1], [{:b, [line: 1], nil}, {:c, [line: 1], nil}]}}
 ]}
iex(24)> Code.string_to_quoted!("%{a => b when c}")
{:%{}, [line: 1],
 [
   {{:a, [line: 1], nil},
    {:when, [line: 1], [{:b, [line: 1], nil}, {:c, [line: 1], nil}]}}
 ]}
iex(25)> Code.string_to_quoted!("%{a => b <- c}")
{:%{}, [line: 1],
 [
   {{:a, [line: 1], nil},
    {:<-, [line: 1], [{:b, [line: 1], nil}, {:c, [line: 1], nil}]}}
 ]}
iex(26)> Code.string_to_quoted!("%{a => b \\\\ c}")
{:%{}, [line: 1],
 [
   {{:a, [line: 1], nil},
    {:\\, [line: 1], [{:b, [line: 1], nil}, {:c, [line: 1], nil}]}}
 ]}

with only exception being %{a | b => c} which is map update syntax

Expected behavior

Precedence table corrected

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions