Skip to content

Commit aae9584

Browse files
committed
Use monomorphic versions of in-place modifying methods
It's not possible to represent side-effects and the receiver type changing, however some type checkers may choose to perform weak updates based on the types passed to these methods and in these situations its useful to still use the original type variables and not method-bound ones.
1 parent 478881a commit aae9584

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

core/array.rbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,8 @@ class Array[unchecked out Elem] < Object
628628
# a #=> ["", "b", "c!", "d!"]
629629
#
630630
# collect! is monomorphic because of RBS limitation.
631-
def collect!: [U] () { (Elem item) -> U } -> ::Array[U]
632-
| () -> ::Enumerator[Elem, ::Array[untyped]]
631+
def collect!: () { (Elem item) -> Elem } -> self
632+
| () -> ::Enumerator[Elem, self]
633633

634634
# When invoked with a block, yields all combinations of length `n` of elements
635635
# from the array and then returns the array itself.

core/hash.rbs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ class Hash[unchecked out K, unchecked out V] < Object
776776
# h = { "a" => 100, "b" => 200 }
777777
# h.replace({ "c" => 300, "d" => 400 }) #=> {"c"=>300, "d"=>400}
778778
#
779-
def replace: [A, B] (Hash[A, B]) -> Hash[A, B]
779+
def replace: (Hash[K, V]) -> self
780780

781781
# Returns a new hash consisting of entries for which the block returns true.
782782
#
@@ -906,8 +906,8 @@ class Hash[unchecked out K, unchecked out V] < Object
906906
#
907907
# If no block is given, an enumerator is returned instead.
908908
#
909-
def transform_keys!: () -> Enumerator[K, Hash[untyped, V]]
910-
| () { (K) -> K } -> Hash[K, V]
909+
def transform_keys!: () -> Enumerator[K, self]
910+
| () { (K) -> K } -> self
911911

912912
# Returns a new hash with the results of running the block once for every value.
913913
# This method does not change the keys.
@@ -935,8 +935,8 @@ class Hash[unchecked out K, unchecked out V] < Object
935935
#
936936
# If no block is given, an enumerator is returned instead.
937937
#
938-
def transform_values!: () -> Enumerator[V, Hash[K, untyped]]
939-
| [A] () { (V) -> A } -> Hash[K, A]
938+
def transform_values!: () -> Enumerator[V, self]
939+
| () { (V) -> V } -> self
940940

941941
# Adds the contents of the given hashes to the receiver.
942942
#

0 commit comments

Comments
 (0)