Skip to content

Commit

Permalink
Use precise language
Browse files Browse the repository at this point in the history
The error message and documentation specifically refers to the variants
of Enumerable#sum/product that do not support union types.
  • Loading branch information
rvprasad committed Dec 28, 2024
1 parent 6b4eea8 commit a09f57b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
12 changes: 6 additions & 6 deletions spec/std/enumerable_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1373,9 +1373,9 @@ describe "Enumerable" do
require "prelude"
[1, 10000000000_u64].sum
CRYSTAL
"Enumerable#sum and #product do not support Union types. Instead, " +
"use Enumerable#sum/product(initial) with an initial value of " +
"the expected type of the call."
"Enumerable#sum() and #product() do not support Union types. " +
"Instead, use Enumerable#sum and #product(initial), respectively, " +
"with an initial value of the intended type of the call."
end

it "uses additive_identity from type" do
Expand Down Expand Up @@ -1427,9 +1427,9 @@ describe "Enumerable" do
require "prelude"
[1, 10000000000_u64].product
CRYSTAL
"Enumerable#sum and #product do not support Union types. Instead, " +
"use Enumerable#sum/product(initial) with an initial value of " +
"the expected type of the call."
"Enumerable#sum() and #product() do not support Union types. " +
"Instead, use Enumerable#sum and #product(initial), respectively, " +
"with an initial value of the intended type of the call."
end
end

Expand Down
7 changes: 4 additions & 3 deletions src/enumerable.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2299,9 +2299,10 @@ module Enumerable(T)
def self.first
{% if X.union? %}
{{
raise("Enumerable#sum and #product do not support Union types. " +
"Instead, use Enumerable#sum/product(initial) with an " +
"initial value of the expected type of the call.")
raise("Enumerable#sum() and #product() do not support Union types. " +
"Instead, use Enumerable#sum and #product(initial), " +
"respectively, with an initial value of the intended type " +
"of the call.")
}}
{% else %}
X
Expand Down

0 comments on commit a09f57b

Please sign in to comment.