Skip to content

Code.Fragment.surround_context miss-categorises atom keys and &1 capture variables #13818

@lukaszsamson

Description

@lukaszsamson

Elixir and Erlang/OTP versions

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

Elixir 1.17.2 (compiled with Erlang/OTP 26)

Operating system

any

Current behavior

  1. It returns local_or_var for atom keys in list, map, etc
iex(5)> Code.Fragment.surround_context("%{foo: 1}", {1, 3})
%{context: {:local_or_var, ~c"foo"}, begin: {1, 3}, end: {1, 6}}

for ordinary atoms it returns unquoted_atom

iex(8)> Code.Fragment.surround_context(":foo", {1, 1})
%{context: {:unquoted_atom, ~c"foo"}, begin: {1, 1}, end: {1, 5}}
  1. It is finding only & operator but in this context & is not an operator but a part of a special variable &123
iex(1)> Code.Fragment.surround_context("&123", {1, 1})
%{context: {:operator, ~c"&"}, begin: {1, 1}, end: {1, 2}}
iex(2)> Code.Fragment.surround_context("&123", {1, 2})
:none

Expected behavior

  1. I would expect it to return unquoted_atom or more specific unquoted_atom_key
  2. Here more appropriate would be local_or_var or something dedicated

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