From 7cc863bd67dd931abafeba666c6e8420156a6690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Pavli=CC=81k?= Date: Thu, 21 Sep 2023 16:19:33 +0200 Subject: [PATCH 1/2] Add tests for guards with maps and the /= operator --- .../refine_comparison_should_pass.erl | 13 +++++++++++++ test/should_pass/refine_comparison.erl | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 test/known_problems/should_pass/refine_comparison_should_pass.erl diff --git a/test/known_problems/should_pass/refine_comparison_should_pass.erl b/test/known_problems/should_pass/refine_comparison_should_pass.erl new file mode 100644 index 00000000..0aad8704 --- /dev/null +++ b/test/known_problems/should_pass/refine_comparison_should_pass.erl @@ -0,0 +1,13 @@ +-module(refine_comparison_should_pass). + +-export([comp_map_value3/1]). + +-type my_map() :: #{value := integer() | nil}. + +-spec comp_map_value3(my_map()) -> integer(). +comp_map_value3(State) when map_get(value, State) /= nil -> + case State of + #{value := Val} -> + Val + 1 + end; +comp_map_value3(#{value := nil}) -> 0. diff --git a/test/should_pass/refine_comparison.erl b/test/should_pass/refine_comparison.erl index 6934b4fe..8e8902dd 100644 --- a/test/should_pass/refine_comparison.erl +++ b/test/should_pass/refine_comparison.erl @@ -28,3 +28,20 @@ compatom1(_) -> ok. -spec compatom2(a | b | c | pid()) -> a | c | pid(). compatom2(X) when X =/= b -> X; compatom2(_) -> a. + +-spec compatom3(a | b | c | pid()) -> a | c | pid(). +compatom3(X) when X /= b -> X; +compatom3(_) -> a. + +-type my_map() :: #{value := integer() | nil}. + +-spec comp_map_value1(my_map()) -> integer(). +comp_map_value1(State) when map_get(value, State) /= nil -> + Val = map_get(value, State), + Val + 1; +comp_map_value1(#{value := nil}) -> 0. + +-spec comp_map_value2(my_map()) -> integer(). +comp_map_value2(#{value := Val}) when Val /= nil -> + Val + 1; +comp_map_value2(#{value := nil}) -> 0. From 6c0ba7d9dee53d4a236e97e9595dde00f491bce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Pavli=CC=81k?= Date: Thu, 21 Sep 2023 16:20:00 +0200 Subject: [PATCH 2/2] Add a known problem for Elixir's List.first/1 function --- .../should_pass/elixir_list_first.erl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/known_problems/should_pass/elixir_list_first.erl diff --git a/test/known_problems/should_pass/elixir_list_first.erl b/test/known_problems/should_pass/elixir_list_first.erl new file mode 100644 index 00000000..5320eba3 --- /dev/null +++ b/test/known_problems/should_pass/elixir_list_first.erl @@ -0,0 +1,17 @@ +-module(elixir_list_first). + +-export([f/0]). + +% This is how List.first/1 is defined in Elixir +-spec first([]) -> nil; + ([Elem, ...]) -> Elem. +first([]) -> nil; +first([Element | _]) -> Element. + +-spec f() -> ok. +f() -> + first(some_list()), + ok. + +-spec some_list() -> list(). +some_list() -> [anything].