Skip to content

Commit

Permalink
Report bad maps -- snapshot tests
Browse files Browse the repository at this point in the history
Summary: Snapshot tests for reporting of bad maps.

Reviewed By: ilya-klyuchnikov

Differential Revision: D62180615

fbshipit-source-id: a785acf4f6a87aa12493eda088ad7f7cf17fe063
  • Loading branch information
VLanvin authored and facebook-github-bot committed Sep 4, 2024
1 parent 87beaca commit 5e1dd10
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/elp/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,7 @@ mod tests {
buck,
EqwalizerConfig {
clause_coverage: Some(true),
report_bad_maps: Some(true),
..EqwalizerConfig::default_test()
},
);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions test_projects/eqwalizer_tests/options/src/bad_maps.erl
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 5e1dd10

Please sign in to comment.