Skip to content

IEx: Autocomplete breaks when called on variable that binds to non-atom. #5576

@Qqwy

Description

@Qqwy

Environment

  • Elixir & Erlang versions (elixir -v):
$ iex --version
Erlang/OTP 19 [erts-8.0] [source] [64-bit] [smp:8:8] [async-threads:10] [kernel-poll:false]

IEx 1.4.0-rc.1 (16a14c1)
  • Operating system: Linux Mint 17.2 rafaela

Current behavior

Try the following code snippet in IEx:

iex(2)> defmodule Foo do
...(2)> defstruct [:a, :b, :c]
...(2)> end
{:module, Foo,
 <<70, 79, 82, 49, 0, 0, 9, 28, 66, 69, 65, 77, 69, 120, 68, 99, 0, 0, 0, 186,
   131, 104, 2, 100, 0, 14, 101, 108, 105, 120, 105, 114, 95, 100, 111, 99, 115,
   95, 118, 49, 108, 0, 0, 0, 4, 104, 2, ...>>, %Foo{a: nil, b: nil, c: nil}}
iex(4)> x = %Foo{}
%Foo{a: nil, b: nil, c: nil}
iex(5)> x.*** ERROR: Shell process terminated! (^G to start new job) ***

09:31:24.596 [error] Process #PID<0.50.0> raised an exception
** (Protocol.UndefinedError) protocol Enumerable not implemented for %Foo{a: nil, b: nil, c: nil}
    (elixir) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir) lib/enum.ex:116: Enumerable.reduce/3
    (elixir) lib/enum.ex:1767: Enum.reduce/3
    (iex) lib/iex/autocomplete.ex:290: IEx.Autocomplete.match_map_fields/2
    (iex) lib/iex/autocomplete.ex:137: IEx.Autocomplete.expand_map_field_access/2
    (kernel) group.erl:568: :group.get_line1/4
    (kernel) group.erl:462: :group.get_chars_loop/8
    (kernel) group.erl:181: :group.io_request/5

(Note: At line (5) I typed x. and then pressed the TAB key to let IEx perform autocompletion.)

The shell is crashed by this, and does not seem to restart by itself, although you can still press Ctrl+C to bring up the BREAK menu.

Expected behavior

I would expect autocompletion to simply not work, i.e. not give any results.

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