diff --git a/lib/stdlib/src/edlin_expand.erl b/lib/stdlib/src/edlin_expand.erl index 8ed43cd5ef20..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/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 4b8f659a3c00..15abaaa7f07e 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,13 +273,10 @@ 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, [], []} = do_expand("complete_function_parameter:multi_arity_fun(["), {no,[], [#{elems := [#{elems := @@ -362,6 +363,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.