Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve compile time error for #sort(&block : T, T -> U) #14693

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/array.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/slice.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/static_array.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Loading