Project

General

Profile

Actions

Bug #15926

closed

Edge case issue with String#uminus

Added by luke-gru (Luke Gruber) over 5 years ago. Updated over 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:93159]

Description

I was working on issue related to code in rb_fstring(https://github.com/ruby/ruby/pull/2233) and saw some weird behavior in the function,
freezing the given string if it's not a "bare" string and it's small enough to be embedded.

The issue comes up in the following edge case:

class MyString < String
end
non_frozen = MyString.new("nonfrozen")
frozen = -non_frozen # deduplicates, but shouldn't freeze receiver
non_frozen << " added" # raises FrozenError

I'm not sure what the correct behavior should be with a subclass and String#uminus. Should it return
a frozen regular String or a frozen copy of the given class's string?

Not a practical concern (not often come upon I'm sure), but I think a valid one.


Files

str-uminus-freeze-fix.patch (1.38 KB) str-uminus-freeze-fix.patch jeremyevans0 (Jeremy Evans), 06/19/2019 02:04 AM
str-uminus-freeze-fix-v2.patch (1.58 KB) str-uminus-freeze-fix-v2.patch jeremyevans0 (Jeremy Evans), 06/19/2019 05:03 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0