Skip to content

Commit dd6b660

Browse files
committed
More
1 parent 0022964 commit dd6b660

5 files changed

Lines changed: 26 additions & 43 deletions

File tree

lib/elixir/lib/module/types/descr.ex

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,23 @@ defmodule Module.Types.Descr do
9999
@boolset :sets.from_list([true, false], version: 2)
100100
def boolean(), do: %{atom: {:union, @boolset}}
101101

102+
@doc """
103+
Gets the upper bound of a gradual type.
104+
105+
This is the same as removing the gradual type.
106+
"""
107+
def upper_bound(%{dynamic: dynamic}), do: dynamic
108+
def upper_bound(static), do: static
109+
110+
@doc """
111+
Gets the lower bound of a gradual type.
112+
113+
This is the same as getting the static part.
114+
Note this is not generally safe and changes the representation of the type.
115+
"""
116+
def lower_bound(:term), do: :term
117+
def lower_bound(type), do: Map.delete(type, :dynamic)
118+
102119
## Function constructors
103120

104121
@doc """
@@ -1120,14 +1137,6 @@ defmodule Module.Types.Descr do
11201137
end
11211138
end
11221139

1123-
# Gets the upper bound of a gradual type.
1124-
defp upper_bound(%{dynamic: dynamic}), do: dynamic
1125-
defp upper_bound(static), do: static
1126-
1127-
# Gets the lower bound of a gradual type.
1128-
defp lower_bound(:term), do: :term
1129-
defp lower_bound(type), do: Map.delete(type, :dynamic)
1130-
11311140
@doc """
11321141
Applies a function type to a list of argument types.
11331142

lib/elixir/lib/module/types/pattern.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,15 @@ defmodule Module.Types.Pattern do
4141

4242
@doc """
4343
Computes the domain from the pattern tree and expected types.
44+
45+
Note we use `upper_bound` because the user of dynamic in the signature
46+
won't make a difference.
4447
"""
4548
def of_domain([{tree, expected, _pattern} | trees], context) do
46-
[intersection(of_pattern_tree(tree, context), expected) | of_domain(trees, context)]
49+
[
50+
intersection(of_pattern_tree(tree, context), expected) |> upper_bound()
51+
| of_domain(trees, context)
52+
]
4753
end
4854

4955
def of_domain([], _context) do

lib/elixir/test/elixir/enum_test.exs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,10 +1192,6 @@ defmodule EnumTest do
11921192
assert_raise FunctionClauseError, fn ->
11931193
Enum.slice(list, 0, -1)
11941194
end
1195-
1196-
assert_raise FunctionClauseError, fn ->
1197-
Enum.slice(list, 0.99, 0)
1198-
end
11991195
end
12001196

12011197
test "slice on infinite streams" do
@@ -2691,14 +2687,6 @@ defmodule EnumTest.Map do
26912687
Enum.slice(map, 0, -1)
26922688
end
26932689

2694-
assert_raise FunctionClauseError, fn ->
2695-
Enum.slice(map, 0.99, 0)
2696-
end
2697-
2698-
assert_raise FunctionClauseError, fn ->
2699-
Enum.slice(map, 0, 0.99)
2700-
end
2701-
27022690
assert Enum.slice(map, 0, 0) == []
27032691
assert Enum.slice(map, 0, 1) == [x1]
27042692
assert Enum.slice(map, 0, 2) == [x1, x2]
@@ -2717,14 +2705,6 @@ defmodule EnumTest.Map do
27172705
assert_raise FunctionClauseError, fn ->
27182706
Enum.slice(map, 0, -1)
27192707
end
2720-
2721-
assert_raise FunctionClauseError, fn ->
2722-
Enum.slice(map, 0.99, 0)
2723-
end
2724-
2725-
assert_raise FunctionClauseError, fn ->
2726-
Enum.slice(map, 0, 0.99)
2727-
end
27282708
end
27292709

27302710
test "reduce/3" do

lib/elixir/test/elixir/kernel/raise_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ defmodule Kernel.RaiseTest do
221221
test "named function clause (stacktrace) or runtime (no stacktrace) error" do
222222
result =
223223
try do
224-
Access.get("foo", 0)
224+
Access.get(Process.get(:unused, "foo"), 0)
225225
rescue
226226
x in [FunctionClauseError, CaseClauseError] -> Exception.message(x)
227227
end
@@ -353,7 +353,7 @@ defmodule Kernel.RaiseTest do
353353
test "function clause error" do
354354
result =
355355
try do
356-
Access.get(:ok, :error)
356+
Access.get(Process.get(:unused, :ok), :error)
357357
rescue
358358
x in [FunctionClauseError] -> Exception.message(x)
359359
end

lib/elixir/test/elixir/range_test.exs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,6 @@ defmodule RangeTest do
7171
end
7272
end
7373

74-
test "limits are integer only" do
75-
first = 1.0
76-
last = 3.0
77-
message = "ranges (first..last) expect both sides to be integers, got: 1.0..3.0"
78-
assert_raise ArgumentError, message, fn -> first..last end
79-
80-
first = []
81-
last = []
82-
message = "ranges (first..last) expect both sides to be integers, got: []..[]"
83-
assert_raise ArgumentError, message, fn -> first..last end
84-
end
85-
8674
test "step is a non-zero integer" do
8775
step = 1.0
8876
message = ~r"the step to be a non-zero integer"

0 commit comments

Comments
 (0)