@@ -818,6 +818,64 @@ defmodule Module.Types.PatternTest do
818818 end
819819 end
820820
821+ describe "equality in guards" do
822+ test "with non-singleton literals" do
823+ assert typecheck! ( [ x ] , x == "foo" , x ) == dynamic ( binary ( ) )
824+ assert typecheck! ( [ x ] , x === "foo" , x ) == dynamic ( binary ( ) )
825+ assert typecheck! ( [ x ] , not ( x == "foo" ) , x ) == dynamic ( )
826+ assert typecheck! ( [ x ] , not ( x === "foo" ) , x ) == dynamic ( )
827+
828+ assert typecheck! ( [ x ] , x != "foo" , x ) == dynamic ( )
829+ assert typecheck! ( [ x ] , x !== "foo" , x ) == dynamic ( )
830+ assert typecheck! ( [ x ] , not ( x != "foo" ) , x ) == dynamic ( binary ( ) )
831+ assert typecheck! ( [ x ] , not ( x !== "foo" ) , x ) == dynamic ( binary ( ) )
832+ end
833+
834+ test "with number literals" do
835+ assert typecheck! ( [ x ] , x == 1 , x ) == dynamic ( union ( integer ( ) , float ( ) ) )
836+ assert typecheck! ( [ x ] , x === 1 , x ) == dynamic ( integer ( ) )
837+ assert typecheck! ( [ x ] , not ( x == 1 ) , x ) == dynamic ( )
838+ assert typecheck! ( [ x ] , not ( x === 1 ) , x ) == dynamic ( )
839+
840+ assert typecheck! ( [ x ] , x != 1 , x ) == dynamic ( )
841+ assert typecheck! ( [ x ] , x !== 1 , x ) == dynamic ( )
842+ assert typecheck! ( [ x ] , not ( x != 1 ) , x ) == dynamic ( union ( integer ( ) , float ( ) ) )
843+ assert typecheck! ( [ x ] , not ( x !== 1 ) , x ) == dynamic ( integer ( ) )
844+
845+ assert typecheck! ( [ x ] , x == 1.0 , x ) == dynamic ( union ( integer ( ) , float ( ) ) )
846+ assert typecheck! ( [ x ] , x === 1.0 , x ) == dynamic ( float ( ) )
847+ assert typecheck! ( [ x ] , not ( x == 1.0 ) , x ) == dynamic ( )
848+ assert typecheck! ( [ x ] , not ( x === 1.0 ) , x ) == dynamic ( )
849+
850+ assert typecheck! ( [ x ] , x != 1.0 , x ) == dynamic ( )
851+ assert typecheck! ( [ x ] , x !== 1.0 , x ) == dynamic ( )
852+ assert typecheck! ( [ x ] , not ( x != 1.0 ) , x ) == dynamic ( union ( integer ( ) , float ( ) ) )
853+ assert typecheck! ( [ x ] , not ( x !== 1.0 ) , x ) == dynamic ( float ( ) )
854+ end
855+
856+ test "with singleton literals" do
857+ assert typecheck! ( [ x ] , x == :foo , x ) == dynamic ( atom ( [ :foo ] ) )
858+ assert typecheck! ( [ x ] , x === :foo , x ) == dynamic ( atom ( [ :foo ] ) )
859+ assert typecheck! ( [ x ] , not ( x == :foo ) , x ) == dynamic ( negation ( atom ( [ :foo ] ) ) )
860+ assert typecheck! ( [ x ] , not ( x === :foo ) , x ) == dynamic ( negation ( atom ( [ :foo ] ) ) )
861+
862+ assert typecheck! ( [ x ] , x != :foo , x ) == dynamic ( negation ( atom ( [ :foo ] ) ) )
863+ assert typecheck! ( [ x ] , x !== :foo , x ) == dynamic ( negation ( atom ( [ :foo ] ) ) )
864+ assert typecheck! ( [ x ] , not ( x != :foo ) , x ) == dynamic ( atom ( [ :foo ] ) )
865+ assert typecheck! ( [ x ] , not ( x !== :foo ) , x ) == dynamic ( atom ( [ :foo ] ) )
866+
867+ assert typecheck! ( [ x ] , x == [ ] , x ) == dynamic ( empty_list ( ) )
868+ assert typecheck! ( [ x ] , x === [ ] , x ) == dynamic ( empty_list ( ) )
869+ assert typecheck! ( [ x ] , not ( x == [ ] ) , x ) == dynamic ( negation ( empty_list ( ) ) )
870+ assert typecheck! ( [ x ] , not ( x === [ ] ) , x ) == dynamic ( negation ( empty_list ( ) ) )
871+
872+ assert typecheck! ( [ x ] , x != [ ] , x ) == dynamic ( negation ( empty_list ( ) ) )
873+ assert typecheck! ( [ x ] , x !== [ ] , x ) == dynamic ( negation ( empty_list ( ) ) )
874+ assert typecheck! ( [ x ] , not ( x != [ ] ) , x ) == dynamic ( empty_list ( ) )
875+ assert typecheck! ( [ x ] , not ( x !== [ ] ) , x ) == dynamic ( empty_list ( ) )
876+ end
877+ end
878+
821879 describe "comparison in guards" do
822880 test "length equality" do
823881 assert typecheck! ( [ x ] , length ( x ) != 0 , x ) == dynamic ( non_empty_list ( term ( ) ) )
0 commit comments