File 0218-edlin_expand-Fix-expansion-of-maps-keys-that-are-not.patch of Package erlang
From af3d7968c3370c37fd2affb96292343477acb951 Mon Sep 17 00:00:00 2001
From: Lukas Larsson <lukas@erlang.org>
Date: Fri, 12 Apr 2024 11:43:03 +0200
Subject: [PATCH 2/3] edlin_expand: Fix expansion of maps keys that are not
atoms
fixes #8365
---
lib/stdlib/src/edlin_type_suggestion.erl | 11 ++++++++---
lib/stdlib/test/edlin_expand_SUITE.erl | 4 ++++
.../complete_function_parameter.erl | 7 ++++++-
3 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/lib/stdlib/src/edlin_type_suggestion.erl b/lib/stdlib/src/edlin_type_suggestion.erl
index 055091b005..1dcbb53b0a 100644
--- a/lib/stdlib/src/edlin_type_suggestion.erl
+++ b/lib/stdlib/src/edlin_type_suggestion.erl
@@ -295,7 +295,9 @@ get_arity1({map, Types}, _Constraints, [{'map', _Keys, [], _, _}]) ->
get_arity1({map, Types}, _Constraints, [{'map', _Keys, _Key, _, _}]) ->
length(Types);
get_arity1({map, Types}, Constraints, [{'map', Keys, [], _, _}|Nestings]) ->
- lists:flatten([get_arity1(T, Constraints, Nestings) || {_, Key, _}=T <- Types, not lists:member(atom_to_list(Key), Keys)]);
+ lists:flatten([get_arity1(T, Constraints, Nestings) ||
+ {_, Key, _}=T <- Types,
+ not lists:member(catch atom_to_list(Key), Keys)]);
get_arity1({map, Types}, Constraints, [{'map', _Keys, Key, _, _}|Nestings]) ->
case [V || {_, K, V} <- Types, K =:= list_to_atom(Key)] of
[] -> none;
@@ -334,7 +336,9 @@ get_atoms1({tuple, LT}, Constraints, [{'tuple', Args, _}|Nestings]) when length(
false -> []
end;
get_atoms1({map, Types}, Constraints, [{'map', Keys, [], _, _}|Nestings]) ->
- lists:flatten([get_atoms1(T, Constraints, Nestings) || {_, Key, _}=T <- Types, not lists:member(atom_to_list(Key), Keys)]);
+ lists:flatten([get_atoms1(T, Constraints, Nestings) ||
+ {_, Key, _}=T <- Types,
+ not lists:member(catch atom_to_list(Key), Keys)]);
get_atoms1({map, Types}, Constraints, [{'map', _Keys, Key, _, _}|Nestings]) ->
case [V || {_, K, V} <- Types, K =:= list_to_atom(Key)] of
[] -> [];
@@ -379,7 +383,8 @@ get_types1({tuple, LT}, Cs, [{tuple, Args, _}|Nestings], MaxUserTypeExpansions,
false -> []
end;
get_types1({'map', Types}, Cs, [{'map', Keys, [], _Args, _}|Nestings], MaxUserTypeExpansions, Options) ->
- lists:flatten([get_types1(T, Cs, Nestings, MaxUserTypeExpansions, Options) || {_, Key, _}=T <- Types, not lists:member(atom_to_list(Key), Keys)]);
+ lists:flatten([get_types1(T, Cs, Nestings, MaxUserTypeExpansions, Options) ||
+ {_, Key, _}=T <- Types, not lists:member(catch atom_to_list(Key), Keys)]);
get_types1({'map', Types}, Cs, [{'map', _, Key, _Args, _}|Nestings], MaxUserTypeExpansions, Options) ->
case [V || {_, K, V} <- Types, K =:= list_to_atom(Key)] of
[] -> [];
diff --git a/lib/stdlib/test/edlin_expand_SUITE.erl b/lib/stdlib/test/edlin_expand_SUITE.erl
index dcd9a19b39..39baac3e9d 100644
--- a/lib/stdlib/test/edlin_expand_SUITE.erl
+++ b/lib/stdlib/test/edlin_expand_SUITE.erl
@@ -362,6 +362,10 @@ get_coverage(Config) ->
do_expand("complete_function_parameter:map_parameter_function(#{}, "),
do_expand("complete_function_parameter:map_parameter_function(#{V=>1}, "),
do_expand("complete_function_parameter:map_parameter_function(#{a=>V}, "),
+ do_expand("complete_function_parameter:map_variable_parameter_function(#{"),
+ do_expand("complete_function_parameter:map_variable_parameter_function(#{a"),
+ do_expand("complete_function_parameter:map_variable_parameter_function(#{a => "),
+ do_expand("complete_function_parameter:map_variable_parameter_function(#{a => a"),
do_expand("complete_function_parameter:tuple_parameter_function({a,b}, "),
do_expand("complete_function_parameter:tuple_parameter_function({a,V}, "),
do_expand("complete_function_parameter:list_parameter_function([], "),
diff --git a/lib/stdlib/test/edlin_expand_SUITE_data/complete_function_parameter.erl b/lib/stdlib/test/edlin_expand_SUITE_data/complete_function_parameter.erl
index 3e7ea2f6a7..8fbe7b27b7 100644
--- a/lib/stdlib/test/edlin_expand_SUITE_data/complete_function_parameter.erl
+++ b/lib/stdlib/test/edlin_expand_SUITE_data/complete_function_parameter.erl
@@ -34,6 +34,7 @@
'emoji_function🤯'/1,
map_parameter_function/1,
map_parameter_function/2,
+ map_variable_parameter_function/2,
tuple_parameter_function/2,
list_parameter_function/2,
non_empty_list_parameter_function/2,
@@ -108,11 +109,15 @@ test_year(_Y) -> 0.
'emoji_function🤯'(_) -> 0.
-spec map_parameter_function(Map) -> boolean() when
- Map :: #{a => 1, b => 2, c => 3, d => error}.
+ Map :: #{ integer() := a, a => 1, b => 2, c => 3, d => error}.
map_parameter_function(_) -> false.
-spec map_parameter_function(Map, any()) -> boolean() when
Map :: #{a => 1, b => 2, c => 3, d => error}.
map_parameter_function(_,_) -> false.
+-spec map_variable_parameter_function(Key, Map) -> Value when
+ Map :: #{ Key => Value, _ => _}.
+map_variable_parameter_function(_, _) ->
+ false.
-spec binary_parameter_function(binary(), any()) -> boolean().
binary_parameter_function(_,_) -> false.
--
2.35.3