-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add opportunistic warnings for shadowed map patterns
The compiler can emit so-called *opportunistic warnings*, which are warnings emitted when the compiler notices something suspicious during optimization or code generation. The trouble with opportunistic warnings is that there is no guarantee that the compiler will notice all kind of suspicious code. For example, the compiler in Erlang/OTP 27 and earlier would not emit any warnings for the following functions: mm_1(#{}) -> a; mm_1(#{first := First}) -> {b,First}. mm_2(#{first := First}) -> {b,First}; mm_2(#{first := First, second := Second}) -> {c,First,Second}. Since it is easy to arrange clauses in the wrong order and put the matching for any map before other map patterns, it seems worthwhile to catch at least some of the map patterns that will shadow subsequent patterns. With this commit, the compiler will generate the following warnings: t.erl:6:1: Warning: this clause cannot match because a previous clause at line 4 matches the same pattern as this clause % 6| mm_1(#{first := First}) -> % | ^ t.erl:11:1: Warning: this clause cannot match because a previous clause at line 9 matches the same pattern as this clause % 11| mm_2(#{first := First, second := Second}) -> % | ^ Note that these warnings are still opportunistic and there is no guarantee that the compiler will notice all kind of shadowed map patterns. Resolves #8558
- Loading branch information
Showing
2 changed files
with
113 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters