diff --git a/src/array.cr b/src/array.cr index cef70c4704c7..30425c6869e3 100644 --- a/src/array.cr +++ b/src/array.cr @@ -1658,7 +1658,7 @@ class Array(T) # Raises `ArgumentError` if for any two elements the block returns `nil`. def sort(&block : T, T -> U) : Array(T) forall U {% unless U <= Int32? %} - {% raise "Expected block to return Int32 or Nil, not #{U}" %} + {% raise "Expected block to return Int32 or Nil, not #{U}.\nThe block is supposed to be a custom comparison operation, compatible with `Comparable#<=>`.\nDid you mean to use `#sort_by`?" %} {% end %} dup.sort! &block @@ -1680,7 +1680,7 @@ class Array(T) # Raises `ArgumentError` if for any two elements the block returns `nil`. def unstable_sort(&block : T, T -> U) : Array(T) forall U {% unless U <= Int32? %} - {% raise "Expected block to return Int32 or Nil, not #{U}" %} + {% raise "Expected block to return Int32 or Nil, not #{U}.\nThe block is supposed to be a custom comparison operation, compatible with `Comparable#<=>`.\nDid you mean to use `#unstable_sort_by`?" %} {% end %} dup.unstable_sort!(&block) @@ -1701,7 +1701,7 @@ class Array(T) # :inherit: def sort!(&block : T, T -> U) : self forall U {% unless U <= Int32? %} - {% raise "Expected block to return Int32 or Nil, not #{U}" %} + {% raise "Expected block to return Int32 or Nil, not #{U}.\nThe block is supposed to be a custom comparison operation, compatible with `Comparable#<=>`.\nDid you mean to use `#sort_by!`?" %} {% end %} to_unsafe_slice.sort!(&block) @@ -1711,7 +1711,7 @@ class Array(T) # :inherit: def unstable_sort!(&block : T, T -> U) : self forall U {% unless U <= Int32? %} - {% raise "Expected block to return Int32 or Nil, not #{U}" %} + {% raise "Expected block to return Int32 or Nil, not #{U}.\nThe block is supposed to be a custom comparison operation, compatible with `Comparable#<=>`.\nDid you mean to use `#unstable_sort_by!`?" %} {% end %} to_unsafe_slice.unstable_sort!(&block) diff --git a/src/slice.cr b/src/slice.cr index 7a27218221a2..196a29a768dd 100644 --- a/src/slice.cr +++ b/src/slice.cr @@ -932,7 +932,7 @@ struct Slice(T) # Raises `ArgumentError` if for any two elements the block returns `nil`. def sort(&block : T, T -> U) : self forall U {% unless U <= Int32? %} - {% raise "Expected block to return Int32 or Nil, not #{U}" %} + {% raise "Expected block to return Int32 or Nil, not #{U}.\nThe block is supposed to be a custom comparison operation, compatible with `Comparable#<=>`.\nDid you mean to use `#sort_by`?" %} {% end %} dup.sort! &block @@ -954,7 +954,7 @@ struct Slice(T) # Raises `ArgumentError` if for any two elements the block returns `nil`. def unstable_sort(&block : T, T -> U) : self forall U {% unless U <= Int32? %} - {% raise "Expected block to return Int32 or Nil, not #{U}" %} + {% raise "Expected block to return Int32 or Nil, not #{U}.\nThe block is supposed to be a custom comparison operation, compatible with `Comparable#<=>`.\nDid you mean to use `#unstable_sort_by`?" %} {% end %} dup.unstable_sort!(&block) @@ -1055,7 +1055,7 @@ struct Slice(T) # Raises `ArgumentError` if for any two elements the block returns `nil`. def sort!(&block : T, T -> U) : self forall U {% unless U <= Int32? %} - {% raise "Expected block to return Int32 or Nil, not #{U}" %} + {% raise "Expected block to return Int32 or Nil, not #{U}.\nThe block is supposed to be a custom comparison operation, compatible with `Comparable#<=>`.\nDid you mean to use `#sort_by!`?" %} {% end %} Slice.merge_sort!(self, block) @@ -1098,7 +1098,7 @@ struct Slice(T) # Raises `ArgumentError` if for any two elements the block returns `nil`. def unstable_sort!(&block : T, T -> U) : self forall U {% unless U <= Int32? %} - {% raise "Expected block to return Int32 or Nil, not #{U}" %} + {% raise "Expected block to return Int32 or Nil, not #{U}.\nThe block is supposed to be a custom comparison operation, compatible with `Comparable#<=>`.\nDid you mean to use `#unstable_sort_by!`?" %} {% end %} Slice.intro_sort!(to_unsafe, size, block) diff --git a/src/static_array.cr b/src/static_array.cr index 4cb2b186f200..2c09e21df166 100644 --- a/src/static_array.cr +++ b/src/static_array.cr @@ -228,7 +228,7 @@ struct StaticArray(T, N) # Raises `ArgumentError` if for any two elements the block returns `nil`.= def sort(&block : T, T -> U) : StaticArray(T, N) forall U {% unless U <= Int32? %} - {% raise "Expected block to return Int32 or Nil, not #{U}" %} + {% raise "Expected block to return Int32 or Nil, not #{U}.\nThe block is supposed to be a custom comparison operation, compatible with `Comparable#<=>`.\nDid you mean to use `#sort_by`?" %} {% end %} ary = dup @@ -251,7 +251,7 @@ struct StaticArray(T, N) # Raises `ArgumentError` if for any two elements the block returns `nil`. def unstable_sort(&block : T, T -> U) : StaticArray(T, N) forall U {% unless U <= Int32? %} - {% raise "Expected block to return Int32 or Nil, not #{U}" %} + {% raise "Expected block to return Int32 or Nil, not #{U}.\nThe block is supposed to be a custom comparison operation, compatible with `Comparable#<=>`.\nDid you mean to use `#unstable_sort_by`?" %} {% end %} ary = dup @@ -273,7 +273,7 @@ struct StaticArray(T, N) # :inherit: def sort!(&block : T, T -> U) : self forall U {% unless U <= Int32? %} - {% raise "Expected block to return Int32 or Nil, not #{U}" %} + {% raise "Expected block to return Int32 or Nil, not #{U}.\nThe block is supposed to be a custom comparison operation, compatible with `Comparable#<=>`.\nDid you mean to use `#sort_by!`?" %} {% end %} to_slice.sort!(&block) @@ -283,7 +283,7 @@ struct StaticArray(T, N) # :inherit: def unstable_sort!(&block : T, T -> U) : self forall U {% unless U <= Int32? %} - {% raise "Expected block to return Int32 or Nil, not #{U}" %} + {% raise "Expected block to return Int32 or Nil, not #{U}.\nThe block is supposed to be a custom comparison operation, compatible with `Comparable#<=>`.\nDid you mean to use `#unstable_sort_by!`?" %} {% end %} to_slice.unstable_sort!(&block)