ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:120304] [Ruby master Bug#20966] Unary
@ 2024-12-18 23:17 getajobmike (Mike Perham) via ruby-core
  2024-12-18 23:20 ` [ruby-core:120305] [Ruby master Bug#20966] Unary plus String warns about freezing getajobmike (Mike Perham) via ruby-core
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: getajobmike (Mike Perham) via ruby-core @ 2024-12-18 23:17 UTC (permalink / raw)
  To: ruby-core; +Cc: getajobmike (Mike Perham)

Issue #20966 has been reported by getajobmike (Mike Perham).

----------------------------------------
Bug #20966: Unary 
https://bugs.ruby-lang.org/issues/20966

* Author: getajobmike (Mike Perham)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
/Users/mperham/src/sidekiq/test/profiling_test.rb:49: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information)



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

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

* [ruby-core:120305] [Ruby master Bug#20966] Unary plus String warns about freezing
  2024-12-18 23:17 [ruby-core:120304] [Ruby master Bug#20966] Unary getajobmike (Mike Perham) via ruby-core
@ 2024-12-18 23:20 ` getajobmike (Mike Perham) via ruby-core
  2024-12-18 23:29 ` [ruby-core:120306] " ufuk (Ufuk Kayserilioglu) via ruby-core
  2024-12-18 23:42 ` [ruby-core:120307] " alanwu (Alan Wu) via ruby-core
  2 siblings, 0 replies; 4+ messages in thread
From: getajobmike (Mike Perham) via ruby-core @ 2024-12-18 23:20 UTC (permalink / raw)
  To: ruby-core; +Cc: getajobmike (Mike Perham)

Issue #20966 has been updated by getajobmike (Mike Perham).

Subject changed from Unary  to Unary plus String warns about freezing

My code:

```
    header = +"\x1f\x8b".force_encoding("BINARY")
```

Rubocop says "Use unary plus to get an unfrozen string literal."

But Ruby 3.4rc1 says:

```
profiling_test.rb:49: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information)
```

Should `+"string"` issue a warning like that?

----------------------------------------
Bug #20966: Unary plus String warns about freezing
https://bugs.ruby-lang.org/issues/20966#change-111070

* Author: getajobmike (Mike Perham)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
/Users/mperham/src/sidekiq/test/profiling_test.rb:49: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information)



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

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

* [ruby-core:120306] [Ruby master Bug#20966] Unary plus String warns about freezing
  2024-12-18 23:17 [ruby-core:120304] [Ruby master Bug#20966] Unary getajobmike (Mike Perham) via ruby-core
  2024-12-18 23:20 ` [ruby-core:120305] [Ruby master Bug#20966] Unary plus String warns about freezing getajobmike (Mike Perham) via ruby-core
@ 2024-12-18 23:29 ` ufuk (Ufuk Kayserilioglu) via ruby-core
  2024-12-18 23:42 ` [ruby-core:120307] " alanwu (Alan Wu) via ruby-core
  2 siblings, 0 replies; 4+ messages in thread
From: ufuk (Ufuk Kayserilioglu) via ruby-core @ 2024-12-18 23:29 UTC (permalink / raw)
  To: ruby-core; +Cc: ufuk (Ufuk Kayserilioglu)

Issue #20966 has been updated by ufuk (Ufuk Kayserilioglu).


I think you are being tripped up by the low precedence of the unary operator, which is applied after the whole chain of calls are made. Try parenthesizing the unary plus and the string.

----------------------------------------
Bug #20966: Unary plus String warns about freezing
https://bugs.ruby-lang.org/issues/20966#change-111072

* Author: getajobmike (Mike Perham)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
```
/Users/mperham/src/sidekiq/test/profiling_test.rb:49: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information)
```



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

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

* [ruby-core:120307] [Ruby master Bug#20966] Unary plus String warns about freezing
  2024-12-18 23:17 [ruby-core:120304] [Ruby master Bug#20966] Unary getajobmike (Mike Perham) via ruby-core
  2024-12-18 23:20 ` [ruby-core:120305] [Ruby master Bug#20966] Unary plus String warns about freezing getajobmike (Mike Perham) via ruby-core
  2024-12-18 23:29 ` [ruby-core:120306] " ufuk (Ufuk Kayserilioglu) via ruby-core
@ 2024-12-18 23:42 ` alanwu (Alan Wu) via ruby-core
  2 siblings, 0 replies; 4+ messages in thread
From: alanwu (Alan Wu) via ruby-core @ 2024-12-18 23:42 UTC (permalink / raw)
  To: ruby-core; +Cc: alanwu (Alan Wu)

Issue #20966 has been updated by alanwu (Alan Wu).

Status changed from Open to Rejected

`+"\x1f\x8b".force_encoding("BINARY")` is parsed as
`+( "\x1f\x8b".force_encoding("BINARY") )` and the warning is coming from `force_encoding`.

Try `(+"\x1f\x8b").force_encoding("BINARY")` or `"\x1f\x8b".+@().force_encoding("BINARY")`.

A way to see the order is with ruby/debug:
```shell
$ rdbg -e 'trace call' -e 'c' test.rb
[1, 2] in test.rb
=>   1| Warning[:deprecated] = true
     2| _ = +"a".force_encoding("BINARY")
=>#0	<main> at test.rb:1
(rdbg:commands) trace call
Enable CallTracer (enabled)
(rdbg:commands) c
DEBUGGER (trace/call) #th:1 #depth:2 >  Warning.[]= at test.rb:1
DEBUGGER (trace/call) #th:1 #depth:2 <  Warning.[]= #=> true at test.rb:1
DEBUGGER (trace/call) #th:1 #depth:2 >  String#force_encoding at test.rb:2
DEBUGGER (trace/call) #th:1 #depth:3 >   Warning#warn at test.rb:2
test.rb:2: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information)
DEBUGGER (trace/call) #th:1 #depth:3 <   Warning#warn #=> nil at test.rb:2
DEBUGGER (trace/call) #th:1 #depth:2 <  String#force_encoding #=> "a" at test.rb:2
DEBUGGER (trace/call) #th:1 #depth:2 >  String#+@ at test.rb:2
DEBUGGER (trace/call) #th:1 #depth:2 <  String#+@ #=> "a" at test.rb:2
```

----------------------------------------
Bug #20966: Unary plus String warns about freezing
https://bugs.ruby-lang.org/issues/20966#change-111073

* Author: getajobmike (Mike Perham)
* Status: Rejected
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
```
/Users/mperham/src/sidekiq/test/profiling_test.rb:49: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information)
```



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

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

end of thread, other threads:[~2024-12-18 23:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-18 23:17 [ruby-core:120304] [Ruby master Bug#20966] Unary getajobmike (Mike Perham) via ruby-core
2024-12-18 23:20 ` [ruby-core:120305] [Ruby master Bug#20966] Unary plus String warns about freezing getajobmike (Mike Perham) via ruby-core
2024-12-18 23:29 ` [ruby-core:120306] " ufuk (Ufuk Kayserilioglu) via ruby-core
2024-12-18 23:42 ` [ruby-core:120307] " alanwu (Alan Wu) via ruby-core

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 NNTP newsgroup(s).