ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:92578] [Ruby trunk Bug#15834] Mutating the result of SortedSet.to_a mutates the original set, potentially violating the set's guarantees
       [not found] <redmine.issue-15834.20190507041150@ruby-lang.org>
@ 2019-05-07  4:11 ` viko
  2019-05-07 18:56 ` [ruby-core:92591] " ruby-core
  2019-10-27 23:09 ` [ruby-core:95574] [Ruby master " merch-redmine
  2 siblings, 0 replies; 3+ messages in thread
From: viko @ 2019-05-07  4:11 UTC (permalink / raw)
  To: ruby-core

Issue #15834 has been reported by viko (Viko Viko).

----------------------------------------
Bug #15834: Mutating the result of SortedSet.to_a mutates the original set, potentially violating the set's guarantees
https://bugs.ruby-lang.org/issues/15834

* Author: viko (Viko Viko)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
``` ruby
require 'set'

set = SortedSet[1, 2, 3]
set.to_a << -1
set.to_a << 3
set.each do |x|
  puts x
end

puts
set.add -2
set.each do |x|
  puts x
end
```
```
1
2
3
-1
3

-2
1
2
3
```

As can be seen, this breaks SortedSet's guarantee of ordering *and* Set's guarantee of uniqueness, besides being strange behaviour. Mutating the set normally undoes the changes. This bug only seems to exist for SortedSet, and not for Set itself. Workaround: `dup`.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:92591] [Ruby trunk Bug#15834] Mutating the result of SortedSet.to_a mutates the original set, potentially violating the set's guarantees
       [not found] <redmine.issue-15834.20190507041150@ruby-lang.org>
  2019-05-07  4:11 ` [ruby-core:92578] [Ruby trunk Bug#15834] Mutating the result of SortedSet.to_a mutates the original set, potentially violating the set's guarantees viko
@ 2019-05-07 18:56 ` ruby-core
  2019-10-27 23:09 ` [ruby-core:95574] [Ruby master " merch-redmine
  2 siblings, 0 replies; 3+ messages in thread
From: ruby-core @ 2019-05-07 18:56 UTC (permalink / raw)
  To: ruby-core

Issue #15834 has been updated by marcandre (Marc-Andre Lafortune).

Assignee set to knu (Akinori MUSHA)

----------------------------------------
Bug #15834: Mutating the result of SortedSet.to_a mutates the original set, potentially violating the set's guarantees
https://bugs.ruby-lang.org/issues/15834#change-77952

* Author: viko (Viko Viko)
* Status: Open
* Priority: Normal
* Assignee: knu (Akinori MUSHA)
* Target version: 
* ruby -v: ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
``` ruby
require 'set'

set = SortedSet[1, 2, 3]
set.to_a << -1
set.to_a << 3
set.each do |x|
  puts x
end

puts
set.add -2
set.each do |x|
  puts x
end
```
```
1
2
3
-1
3

-2
1
2
3
```

As can be seen, this breaks SortedSet's guarantee of ordering *and* Set's guarantee of uniqueness, besides being strange behaviour. Mutating the set normally undoes the changes. This bug only seems to exist for SortedSet, and not for Set itself. Workaround: `dup`.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:95574] [Ruby master Bug#15834] Mutating the result of SortedSet.to_a mutates the original set, potentially violating the set's guarantees
       [not found] <redmine.issue-15834.20190507041150@ruby-lang.org>
  2019-05-07  4:11 ` [ruby-core:92578] [Ruby trunk Bug#15834] Mutating the result of SortedSet.to_a mutates the original set, potentially violating the set's guarantees viko
  2019-05-07 18:56 ` [ruby-core:92591] " ruby-core
@ 2019-10-27 23:09 ` merch-redmine
  2 siblings, 0 replies; 3+ messages in thread
From: merch-redmine @ 2019-10-27 23:09 UTC (permalink / raw)
  To: ruby-core

Issue #15834 has been updated by jeremyevans0 (Jeremy Evans).

File sorted-set-to_a-mutate-15834 added

Attached is a patch with a test for fixing this.

----------------------------------------
Bug #15834: Mutating the result of SortedSet.to_a mutates the original set, potentially violating the set's guarantees
https://bugs.ruby-lang.org/issues/15834#change-82356

* Author: viko (Viko Viko)
* Status: Open
* Priority: Normal
* Assignee: knu (Akinori MUSHA)
* Target version: 
* ruby -v: ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
``` ruby
require 'set'

set = SortedSet[1, 2, 3]
set.to_a << -1
set.to_a << 3
set.each do |x|
  puts x
end

puts
set.add -2
set.each do |x|
  puts x
end
```
```
1
2
3
-1
3

-2
1
2
3
```

As can be seen, this breaks SortedSet's guarantee of ordering *and* Set's guarantee of uniqueness, besides being strange behaviour. Mutating the set normally undoes the changes. This bug only seems to exist for SortedSet, and not for Set itself. Workaround: `dup`.

---Files--------------------------------
sorted-set-to_a-mutate-15834 (1.02 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-10-27 23:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-15834.20190507041150@ruby-lang.org>
2019-05-07  4:11 ` [ruby-core:92578] [Ruby trunk Bug#15834] Mutating the result of SortedSet.to_a mutates the original set, potentially violating the set's guarantees viko
2019-05-07 18:56 ` [ruby-core:92591] " ruby-core
2019-10-27 23:09 ` [ruby-core:95574] [Ruby master " merch-redmine

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).