From 5e1dd10bd8c9c8a3ff66cfa3391032c336936e1e Mon Sep 17 00:00:00 2001 From: Victor Lanvin Date: Wed, 4 Sep 2024 08:21:44 -0700 Subject: [PATCH] Report bad maps -- snapshot tests Summary: Snapshot tests for reporting of bad maps. Reviewed By: ilya-klyuchnikov Differential Revision: D62180615 fbshipit-source-id: a785acf4f6a87aa12493eda088ad7f7cf17fe063 --- crates/elp/src/bin/main.rs | 1 + .../eqwalizer_tests/options/bad_maps.pretty | 33 +++++++++++++++++++ .../eqwalizer_tests/options/src/bad_maps.erl | 17 ++++++++++ 3 files changed, 51 insertions(+) create mode 100644 crates/elp/src/resources/test/eqwalizer_tests/options/bad_maps.pretty create mode 100644 test_projects/eqwalizer_tests/options/src/bad_maps.erl diff --git a/crates/elp/src/bin/main.rs b/crates/elp/src/bin/main.rs index 69d3c98ef5..be5d7bb98f 100644 --- a/crates/elp/src/bin/main.rs +++ b/crates/elp/src/bin/main.rs @@ -1755,6 +1755,7 @@ mod tests { buck, EqwalizerConfig { clause_coverage: Some(true), + report_bad_maps: Some(true), ..EqwalizerConfig::default_test() }, ); diff --git a/crates/elp/src/resources/test/eqwalizer_tests/options/bad_maps.pretty b/crates/elp/src/resources/test/eqwalizer_tests/options/bad_maps.pretty new file mode 100644 index 0000000000..019b933995 --- /dev/null +++ b/crates/elp/src/resources/test/eqwalizer_tests/options/bad_maps.pretty @@ -0,0 +1,33 @@ +error: bad_map_key + ┌─ options/src/bad_maps.erl:10:24 + │ +10 │ -type bad_map_1() :: #{atom() := integer()}. + │ ^^^^^^^^^^^^^^^^^ Required map key should always be a singular atom. Map type will be approximated to #{dynamic() => dynamic()}. + +See https://fb.me/eqwalizer_errors#bad_map_key + +error: bad_map_key + ┌─ options/src/bad_maps.erl:12:32 + │ +12 │ -type bad_map_2() :: #{a => b, atom() => integer()}. + │ ^^^^^^^^^^^^^^^^^ With multiple assocations, all keys should be singular atoms. Map type will be approximated to #{dynamic() => dynamic()}. + +See https://fb.me/eqwalizer_errors#bad_map_key + +error: bad_map_key + ┌─ options/src/bad_maps.erl:14:32 + │ +14 │ -type bad_map_3() :: #{a => b, atom() := integer()}. + │ ^^^^^^^^^^^^^^^^^ Required map key should always be a singular atom. Map type will be approximated to #{dynamic() => dynamic()}. + +See https://fb.me/eqwalizer_errors#bad_map_key + +error: bad_map_key + ┌─ options/src/bad_maps.erl:16:30 + │ +16 │ -spec bad_map_spec(#{a => b, atom() => integer()}) -> ok. + │ ^^^^^^^^^^^^^^^^^ With multiple assocations, all keys should be singular atoms. Map type will be approximated to #{dynamic() => dynamic()}. + +See https://fb.me/eqwalizer_errors#bad_map_key + +4 ERRORS diff --git a/test_projects/eqwalizer_tests/options/src/bad_maps.erl b/test_projects/eqwalizer_tests/options/src/bad_maps.erl new file mode 100644 index 0000000000..9fbc0f5689 --- /dev/null +++ b/test_projects/eqwalizer_tests/options/src/bad_maps.erl @@ -0,0 +1,17 @@ +%%% Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved. +%%% +%%% This source code is licensed under the Apache 2.0 license found in +%%% the LICENSE file in the root directory of this source tree. + +-module(bad_maps). + +-compile([export_all, nowarn_export_all]). + +-type bad_map_1() :: #{atom() := integer()}. + +-type bad_map_2() :: #{a => b, atom() => integer()}. + +-type bad_map_3() :: #{a => b, atom() := integer()}. + +-spec bad_map_spec(#{a => b, atom() => integer()}) -> ok. + bad_map_spec(M) -> ok.