From 28a5b71aa15f091480f43e0f47a67a4a765975b8 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Fri, 12 Apr 2024 10:45:04 +0200 Subject: [PATCH 1/3] edlin_expand: Fix expansion of zero-arity functions fixes #8364 --- lib/stdlib/src/edlin_expand.erl | 2 +- lib/stdlib/test/edlin_expand_SUITE.erl | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/stdlib/src/edlin_expand.erl b/lib/stdlib/src/edlin_expand.erl index 8ed43cd5ef20..b385b6b40cad 100644 --- a/lib/stdlib/src/edlin_expand.erl +++ b/lib/stdlib/src/edlin_expand.erl @@ -480,7 +480,7 @@ expand_function_parameter_type(Mod, MFA, FunType, Args, Unfinished, Nestings, FT end, case match_arguments(TypeTree, Args) of false -> {no, [], []}; - true when Parameters == [] -> {yes, ")", [#{title=>MFA, elems=>[")"], options=>[]}]}; + true when Parameters == [] -> {yes, ")", [#{title=>MFA, elems=>[{")",[]}], options=>[]}]}; true -> Parameter = lists:nth(length(Args)+1, Parameters), {T, _Name} = case Parameter of diff --git a/lib/stdlib/test/edlin_expand_SUITE.erl b/lib/stdlib/test/edlin_expand_SUITE.erl index 4b8f659a3c00..dcd9a19b39a9 100644 --- a/lib/stdlib/test/edlin_expand_SUITE.erl +++ b/lib/stdlib/test/edlin_expand_SUITE.erl @@ -259,6 +259,10 @@ function_parameter_completion(Config) -> {no, [], [#{elems:=[#{elems:=[#{elems:=[{"any()",[]},{"[any() | [Deeplist]]",[]}]}]}]}]} = do_expand("complete_function_parameter:a_deeplist_fun("), {no,[],[#{title:="typespecs", elems:=[#{title:= + "complete_function_parameter:multi_arity_fun()", + options:=[], + elems:=[{")",[]}]}, + #{title:= "complete_function_parameter:multi_arity_fun(T1)", elems:=[#{title:="types", elems:=[{"integer()",[]}], @@ -269,11 +273,7 @@ function_parameter_completion(Config) -> elems:=[#{title:="types", elems:=[{"integer()",[]}], options:=[{hide,title}]}], - options:=[{highlight_param,1}]}, - #{title:= - "complete_function_parameter:multi_arity_fun()", - options:=[], - elems:=[")"]}], + options:=[{highlight_param,1}]}], options:=[highlight_all]}]} = do_expand("complete_function_parameter:multi_arity_fun("), {no, [], [#{elems:=[#{elems:=[#{elems:=[{"true",[]},{"false",[]}]}]}]}]} = do_expand("complete_function_parameter:multi_arity_fun(1,"), {no,[], From af3d7968c3370c37fd2affb96292343477acb951 Mon Sep 17 00:00:00 2001 From: Lukas Larsson 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 055091b005e4..1dcbb53b0a5b 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 dcd9a19b39a9..39baac3e9d14 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 3e7ea2f6a76e..8fbe7b27b73b 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. From fb4e4179fde5447e3e2bf86a1a3b9a35743430f7 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Fri, 12 Apr 2024 14:33:52 +0200 Subject: [PATCH 3/3] edlin_expand: Exclude zero-arity functions when a nesting exists fixes #8366 --- lib/stdlib/src/edlin_expand.erl | 7 ++++++- lib/stdlib/test/edlin_expand_SUITE.erl | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/stdlib/src/edlin_expand.erl b/lib/stdlib/src/edlin_expand.erl index b385b6b40cad..444483a1b743 100644 --- a/lib/stdlib/src/edlin_expand.erl +++ b/lib/stdlib/src/edlin_expand.erl @@ -480,7 +480,12 @@ expand_function_parameter_type(Mod, MFA, FunType, Args, Unfinished, Nestings, FT end, case match_arguments(TypeTree, Args) of false -> {no, [], []}; - true when Parameters == [] -> {yes, ")", [#{title=>MFA, elems=>[{")",[]}], options=>[]}]}; + true when Parameters == [] -> + if Nestings == [] -> + {yes, ")", [#{title=>MFA, elems=>[{")",[]}], options=>[]}]}; + true -> + {no, [], []} + end; true -> Parameter = lists:nth(length(Args)+1, Parameters), {T, _Name} = case Parameter of diff --git a/lib/stdlib/test/edlin_expand_SUITE.erl b/lib/stdlib/test/edlin_expand_SUITE.erl index 39baac3e9d14..15abaaa7f07e 100644 --- a/lib/stdlib/test/edlin_expand_SUITE.erl +++ b/lib/stdlib/test/edlin_expand_SUITE.erl @@ -276,6 +276,7 @@ function_parameter_completion(Config) -> options:=[{highlight_param,1}]}], options:=[highlight_all]}]} = do_expand("complete_function_parameter:multi_arity_fun("), {no, [], [#{elems:=[#{elems:=[#{elems:=[{"true",[]},{"false",[]}]}]}]}]} = do_expand("complete_function_parameter:multi_arity_fun(1,"), + {no, [], []} = do_expand("complete_function_parameter:multi_arity_fun(["), {no,[], [#{elems := [#{elems :=