Skip to content

Commit b27b911

Browse files
committedMar 25, 2025·
Remove struct comparison specific warning
Now that we have added inference, there are too many false positives. However, note we still have a disjoint check warning, which will still warn about several cases of structs. Closes #13227. Closes #14359.
1 parent f0fc792 commit b27b911

File tree

2 files changed

+0
-66
lines changed

2 files changed

+0
-66
lines changed
 

‎lib/elixir/lib/module/types/apply.ex

-33
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,6 @@ defmodule Module.Types.Apply do
433433
not check? ->
434434
{:ok, result}
435435

436-
match?({false, _}, map_fetch(left, :__struct__)) or
437-
match?({false, _}, map_fetch(right, :__struct__)) ->
438-
{:error, :struct_comparison}
439-
440436
number_type?(left) and number_type?(right) ->
441437
{:ok, result}
442438

@@ -983,35 +979,6 @@ defmodule Module.Types.Apply do
983979
}
984980
end
985981

986-
def format_diagnostic({:struct_comparison, [left, right], mfac, expr, context}) do
987-
{_, name, _, _} = mfac
988-
traces = collect_traces(expr, context)
989-
990-
%{
991-
details: %{typing_traces: traces},
992-
message:
993-
IO.iodata_to_binary([
994-
"""
995-
comparison with structs found:
996-
997-
#{expr_to_string(expr) |> indent(4)}
998-
999-
given types:
1000-
1001-
#{type_comparison_to_string(name, left, right) |> indent(4)}
1002-
""",
1003-
format_traces(traces),
1004-
"""
1005-
1006-
Comparison operators (>, <, >=, <=, min, and max) perform structural \
1007-
and not semantic comparison. Comparing with a struct won't give meaningful \
1008-
results. Structs that can be compared typically define a compare/2 function \
1009-
within their modules that can be used for semantic comparison.
1010-
"""
1011-
])
1012-
}
1013-
end
1014-
1015982
def format_diagnostic({:undefined, :badmodule, module, fun, arity}) do
1016983
top =
1017984
if fun == :__struct__ and arity == 0 do

‎lib/elixir/test/elixir/module/types/expr_test.exs

-33
Original file line numberDiff line numberDiff line change
@@ -1067,39 +1067,6 @@ defmodule Module.Types.ExprTest do
10671067
which are always disjoint, and the result is either always true or always false
10681068
"""
10691069
end
1070-
1071-
test "warns on comparison with struct across dynamic call" do
1072-
assert typeerror!([x = :foo, y = %Point{}, mod = Kernel], mod.<=(x, y)) ==
1073-
~l"""
1074-
comparison with structs found:
1075-
1076-
mod.<=(x, y)
1077-
1078-
given types:
1079-
1080-
dynamic(:foo) <= dynamic(%Point{})
1081-
1082-
where "mod" was given the type:
1083-
1084-
# type: dynamic(Kernel)
1085-
# from: types_test.ex:LINE-1
1086-
mod = Kernel
1087-
1088-
where "x" was given the type:
1089-
1090-
# type: dynamic(:foo)
1091-
# from: types_test.ex:LINE-1
1092-
x = :foo
1093-
1094-
where "y" was given the type:
1095-
1096-
# type: dynamic(%Point{})
1097-
# from: types_test.ex:LINE-1
1098-
y = %Point{}
1099-
1100-
Comparison operators (>, <, >=, <=, min, and max) perform structural and not semantic comparison. Comparing with a struct won't give meaningful results. Structs that can be compared typically define a compare/2 function within their modules that can be used for semantic comparison.
1101-
"""
1102-
end
11031070
end
11041071

11051072
describe ":erlang rewrites" do

0 commit comments

Comments
 (0)
Please sign in to comment.