ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:91609] [Ruby trunk Bug#15616] Chained destructive methods fail when using +@to unfreeze a frozen string
       [not found] <redmine.issue-15616.20190222145228@ruby-lang.org>
@ 2019-02-22 14:52 ` cianol
  2019-02-22 15:51 ` [ruby-core:91610] " pdahorek
  2019-02-25  6:14 ` [ruby-core:91619] [Ruby trunk Bug#15616] Chained destructive methods fail when using +@ to " duerst
  2 siblings, 0 replies; 3+ messages in thread
From: cianol @ 2019-02-22 14:52 UTC (permalink / raw)
  To: ruby-core

Issue #15616 has been reported by cianooooo (Cian O).

----------------------------------------
Bug #15616: Chained destructive methods fail when using +@ to unfreeze a frozen string
https://bugs.ruby-lang.org/issues/15616

* Author: cianooooo (Cian O)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.6.1
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Using the +@ syntax to unfreeze a string does not work when chaining destructive methods

Consider the following;
``` ruby
foo = "bar".freeze
+foo.gsub!("bar", "car")
```

This raises;
``` ruby
FrozenError: can't modify frozen String
```

However, I would have expected this to work since +@ should return a duplicated mutable string.



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

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

* [ruby-core:91610] [Ruby trunk Bug#15616] Chained destructive methods fail when using +@to unfreeze a frozen string
       [not found] <redmine.issue-15616.20190222145228@ruby-lang.org>
  2019-02-22 14:52 ` [ruby-core:91609] [Ruby trunk Bug#15616] Chained destructive methods fail when using +@to unfreeze a frozen string cianol
@ 2019-02-22 15:51 ` pdahorek
  2019-02-25  6:14 ` [ruby-core:91619] [Ruby trunk Bug#15616] Chained destructive methods fail when using +@ to " duerst
  2 siblings, 0 replies; 3+ messages in thread
From: pdahorek @ 2019-02-22 15:51 UTC (permalink / raw)
  To: ruby-core

Issue #15616 has been updated by ahorek (Pavel Rosický).


```
+foo.gsub!("bar", "car")
```
 stands for
```
+(foo.gsub!("bar", "car"))
```
and because foo is frozen, you'll get an error, see #15606


try this
```
foo = "bar".freeze
foo = (+foo).gsub!("bar", "car")
```
or
```
foo = "bar".freeze
foo = foo.gsub("bar", "car")
```


----------------------------------------
Bug #15616: Chained destructive methods fail when using +@ to unfreeze a frozen string
https://bugs.ruby-lang.org/issues/15616#change-76877

* Author: cianooooo (Cian O)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.6.1
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Using the +@ syntax to unfreeze a string does not work when chaining destructive methods

Consider the following;
``` ruby
foo = "bar".freeze
+foo.gsub!("bar", "car")
```

This raises;
``` ruby
FrozenError: can't modify frozen String
```

However, I would have expected this to work since +@ should return a duplicated mutable string.



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

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

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

* [ruby-core:91619] [Ruby trunk Bug#15616] Chained destructive methods fail when using +@ to unfreeze a frozen string
       [not found] <redmine.issue-15616.20190222145228@ruby-lang.org>
  2019-02-22 14:52 ` [ruby-core:91609] [Ruby trunk Bug#15616] Chained destructive methods fail when using +@to unfreeze a frozen string cianol
  2019-02-22 15:51 ` [ruby-core:91610] " pdahorek
@ 2019-02-25  6:14 ` duerst
  2 siblings, 0 replies; 3+ messages in thread
From: duerst @ 2019-02-25  6:14 UTC (permalink / raw)
  To: ruby-core

Issue #15616 has been updated by duerst (Martin Dürst).

Status changed from Open to Rejected

Yes. It's a matter of precedence. The "Pickaxe" book describes it as

> Single terms in an expression may be any of the following:
> 
> [some cases omitted]
> 
> - Method invocation

That means that in ```+foo.gsub!("bar", "car")```, the `.` of method invocation has higher precedence than the `+`, and so you need to use parentheses if you want to change the order of evaluation.

----------------------------------------
Bug #15616: Chained destructive methods fail when using +@ to unfreeze a frozen string
https://bugs.ruby-lang.org/issues/15616#change-76883

* Author: cianooooo (Cian O)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.6.1
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Using the +@ syntax to unfreeze a string does not work when chaining destructive methods

Consider the following;
``` ruby
foo = "bar".freeze
+foo.gsub!("bar", "car")
```

This raises;
``` ruby
FrozenError: can't modify frozen String
```

However, I would have expected this to work since +@ should return a duplicated mutable string.



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

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

end of thread, other threads:[~2019-02-25  6:15 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-15616.20190222145228@ruby-lang.org>
2019-02-22 14:52 ` [ruby-core:91609] [Ruby trunk Bug#15616] Chained destructive methods fail when using +@to unfreeze a frozen string cianol
2019-02-22 15:51 ` [ruby-core:91610] " pdahorek
2019-02-25  6:14 ` [ruby-core:91619] [Ruby trunk Bug#15616] Chained destructive methods fail when using +@ to " duerst

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).