Created
October 26, 2021 17:10
-
-
Save elbrujohalcon/96bf8b88af7fe6bcfbb1a8fa02ae8543 to your computer and use it in GitHub Desktop.
Shadowing clauses detection
This file contains hidden or 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
-module(el). | |
-export([warn/2, warn_case/1]). | |
-export([clean/2, clean_case/1]). | |
warn(X, Y) -> | |
{just, X and Y}; | |
warn(6, 6) -> | |
{six, 6}. | |
warn_case(X) -> | |
{_, X} = | |
if X == 6 -> | |
{six, 6}; | |
is_integer(X) andalso X == 6 -> | |
{also_six, 6}; | |
true -> | |
{other, X}; | |
true -> | |
{yet_another, X} | |
end, | |
case X of | |
_ -> | |
{just, X}; | |
6 -> | |
{six, 6}; | |
X -> | |
{other, X} | |
end. | |
clean_case(X) -> | |
case X of | |
X -> | |
{just, X}; | |
X when X == 6 -> | |
{six, 6}; | |
6 -> | |
{still_six, 6}; | |
X when X == 6 -> | |
{six_again, 6}; | |
X -> | |
{other, X} | |
end. | |
clean(V, V) -> | |
{same, V}; | |
clean(X, Y) when X == Y -> | |
{also_same, X}; | |
clean(6, 6) -> | |
{six, 6}; | |
clean(X, Y) -> | |
case {X, Y} of | |
{V, V} -> | |
{same, V}; | |
{X, Y} when X == Y -> | |
{also_same, X}; | |
{6, 6} -> | |
{six, 6}; | |
{X, Y} -> | |
{other, X, Y} | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment