Skip to content

Commit

Permalink
Fix crashing on autocompleting structs with runtime values (#14150)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeMilan authored Jan 7, 2025
1 parent 9256143 commit ef1450d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/iex/lib/iex/autocomplete.ex
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ defmodule IEx.Autocomplete do
end)

entries =
for {key, _value} <- pairs,
for key when key != :__struct__ <- Map.keys(pairs),
name = Atom.to_string(key),
if(hint == "",
do: not String.starts_with?(name, "_"),
Expand Down
13 changes: 13 additions & 0 deletions lib/iex/test/iex/autocomplete_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,19 @@ defmodule IEx.AutocompleteTest do
assert {:yes, ~c"ry: ", []} = expand(~c"%URI{var | path: \"foo\", que")
assert {:no, [], []} = expand(~c"%URI{var | path: \"foo\", unkno")
assert {:no, [], []} = expand(~c"%Unknown{var | path: \"foo\", unkno")

eval("var = %URI{}")

assert {:yes, ~c"", entries} = expand(~c"%{var | ")
assert ~c"path:" in entries
assert ~c"query:" in entries

assert {:yes, ~c"", entries} = expand(~c"%{var | path: \"foo\",")
assert ~c"path:" not in entries
assert ~c"query:" in entries

assert {:yes, ~c"ry: ", []} = expand(~c"%{var | path: \"foo\", que")
assert {:no, [], []} = expand(~c"%URI{var | path: \"foo\", unkno")
end

test "completion for map keys in update syntax" do
Expand Down

0 comments on commit ef1450d

Please sign in to comment.