ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:77801] [Ruby trunk Bug#12881] Double-bang (!!) raises warning on string literal
       [not found] <redmine.issue-12881.20161028173953@ruby-lang.org>
@ 2016-10-28 17:39 ` rrroybbbean
  2016-10-29 18:29 ` [ruby-core:77811] " nagachika00
  1 sibling, 0 replies; 3+ messages in thread
From: rrroybbbean @ 2016-10-28 17:39 UTC (permalink / raw
  To: ruby-core

Issue #12881 has been reported by RRRoy BBBean.

----------------------------------------
Bug #12881: Double-bang (!!) raises warning on string literal
https://bugs.ruby-lang.org/issues/12881

* Author: RRRoy BBBean
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
I use !!x or !!(x) to force x to true or false.
I just noticed this trick raises a warning with string literals.
It would be nice if this warning were not raised, since it is sometimes convenient to force some object to true or false.
I first saw this in irb, but it also happens when running a script from the command line.
Caveat: Although the output of my sample program suggests that double-quoted strings avoid this warning, it actually happens with !!"hi" as well as !!'hi'

CODE: bb.rb
  1 p [ '!!false', !!false ]
  2 p [ '!!(false)', !!(false) ]
  3 p [ '!!nil', !!nil ]
  4 p [ '!!(nil)', !!(nil) ]
  5 p [ '!!true', !!true ]
  6 p [ '!!(true)', !!(true) ]
  7 p [ '!![]', !![] ]
  8 p [ '!!([])', !!([]) ]
  9 p [ '!!{}', !!{} ]
 10 p [ '!!Object.new', !!Object.new ]
 11 p [ '!!(Object.new)', !!(Object.new) ]
 12 p [ '!!1', !!1 ]
 13 p [ '!!(1)', !!(1) ]
 14 p [ '!!0.1', !!0.1 ]
 15 p [ '!!(0.1)', !!(0.1) ]
 16 p [ '!!:a', !!:a ]
 17 p [ '!!(:a)', !!(:a) ]
 18 p [ '!!({})', !!({}) ]
 19 p [ '!!String.new', !!String.new ]
 20 p [ '!!(String.new)', !!(String.new) ]
 21 p [ '!!""', !!"" ]
 22 p [ '!!("")', !!("") ]
 23 p [ '!!"b"', !!"b" ]
 24 p [ '!!("b")', !!("b") ]
 25 p [ "!!''", !!'' ]
 26 p [ "!!('')", !!('') ]
 27 p [ "!!'b'", !!'b' ]
 28 p [ "!!('b')", !!('b') ]

OUTPUT
bb.rb:25: warning: string literal in condition
bb.rb:26: warning: string literal in condition
bb.rb:27: warning: string literal in condition
bb.rb:28: warning: string literal in condition
["!!false", false]
["!!(false)", false]
["!!nil", false]
["!!(nil)", false]
["!!true", true]
["!!(true)", true]
["!![]", true]
["!!([])", true]
["!!{}", true]
["!!Object.new", true]
["!!(Object.new)", true]
["!!1", true]
["!!(1)", true]
["!!0.1", true]
["!!(0.1)", true]
["!!:a", true]
["!!(:a)", true]
["!!({})", true]
["!!String.new", true]
["!!(String.new)", true]
["!!\"\"", true]
["!!(\"\")", true]
["!!\"b\"", true]
["!!(\"b\")", true]
["!!''", true]
["!!('')", true]
["!!'b'", true]
["!!('b')", true]

ruby --version
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
I compiled it myself from sources, running on Fedora24 amd64 workstation




---Files--------------------------------
bb.rb (685 Bytes)


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

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

* [ruby-core:77811] [Ruby trunk Bug#12881] Double-bang (!!) raises warning on string literal
       [not found] <redmine.issue-12881.20161028173953@ruby-lang.org>
  2016-10-28 17:39 ` [ruby-core:77801] [Ruby trunk Bug#12881] Double-bang (!!) raises warning on string literal rrroybbbean
@ 2016-10-29 18:29 ` nagachika00
  2016-10-30  0:23   ` [ruby-core:77815] " RRRoy BBBean
  1 sibling, 1 reply; 3+ messages in thread
From: nagachika00 @ 2016-10-29 18:29 UTC (permalink / raw
  To: ruby-core

Issue #12881 has been updated by Tomoyuki Chikanaga.

Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: REQUIRED

----------------------------------------
Bug #12881: Double-bang (!!) raises warning on string literal
https://bugs.ruby-lang.org/issues/12881#change-61117

* Author: RRRoy BBBean
* Status: Closed
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: REQUIRED
----------------------------------------
I use !!x or !!(x) to force x to true or false.
I just noticed this trick raises a warning with string literals.
It would be nice if this warning were not raised, since it is sometimes convenient to force some object to true or false.
I first saw this in irb, but it also happens when running a script from the command line.
Caveat: Although the output of my sample program suggests that double-quoted strings avoid this warning, it actually happens with !!"hi" as well as !!'hi'

CODE: bb.rb
  1 p [ '!!false', !!false ]
  2 p [ '!!(false)', !!(false) ]
  3 p [ '!!nil', !!nil ]
  4 p [ '!!(nil)', !!(nil) ]
  5 p [ '!!true', !!true ]
  6 p [ '!!(true)', !!(true) ]
  7 p [ '!![]', !![] ]
  8 p [ '!!([])', !!([]) ]
  9 p [ '!!{}', !!{} ]
 10 p [ '!!Object.new', !!Object.new ]
 11 p [ '!!(Object.new)', !!(Object.new) ]
 12 p [ '!!1', !!1 ]
 13 p [ '!!(1)', !!(1) ]
 14 p [ '!!0.1', !!0.1 ]
 15 p [ '!!(0.1)', !!(0.1) ]
 16 p [ '!!:a', !!:a ]
 17 p [ '!!(:a)', !!(:a) ]
 18 p [ '!!({})', !!({}) ]
 19 p [ '!!String.new', !!String.new ]
 20 p [ '!!(String.new)', !!(String.new) ]
 21 p [ '!!""', !!"" ]
 22 p [ '!!("")', !!("") ]
 23 p [ '!!"b"', !!"b" ]
 24 p [ '!!("b")', !!("b") ]
 25 p [ "!!''", !!'' ]
 26 p [ "!!('')", !!('') ]
 27 p [ "!!'b'", !!'b' ]
 28 p [ "!!('b')", !!('b') ]

OUTPUT
bb.rb:25: warning: string literal in condition
bb.rb:26: warning: string literal in condition
bb.rb:27: warning: string literal in condition
bb.rb:28: warning: string literal in condition
["!!false", false]
["!!(false)", false]
["!!nil", false]
["!!(nil)", false]
["!!true", true]
["!!(true)", true]
["!![]", true]
["!!([])", true]
["!!{}", true]
["!!Object.new", true]
["!!(Object.new)", true]
["!!1", true]
["!!(1)", true]
["!!0.1", true]
["!!(0.1)", true]
["!!:a", true]
["!!(:a)", true]
["!!({})", true]
["!!String.new", true]
["!!(String.new)", true]
["!!\"\"", true]
["!!(\"\")", true]
["!!\"b\"", true]
["!!(\"b\")", true]
["!!''", true]
["!!('')", true]
["!!'b'", true]
["!!('b')", true]

ruby --version
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
I compiled it myself from sources, running on Fedora24 amd64 workstation




---Files--------------------------------
bb.rb (685 Bytes)


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

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

* [ruby-core:77815] Re: [Ruby trunk Bug#12881] Double-bang (!!) raises warning on string literal
  2016-10-29 18:29 ` [ruby-core:77811] " nagachika00
@ 2016-10-30  0:23   ` RRRoy BBBean
  0 siblings, 0 replies; 3+ messages in thread
From: RRRoy BBBean @ 2016-10-30  0:23 UTC (permalink / raw
  To: ruby-core

This is a follow-up. I tested for the same issue with Ruby 2.4.0 preview 
2. I got slightly different behavior, but essentially the same issue. 
Here are the details. I wasn't sure if I could add them to the issue 
tracker without making a mess, so I posted them here.

I downloaded Ruby 2.4.0 preview 2 and built it alongside 2.3.1. The 
configure and make ran fine. I did not install 2.4.0p2, but I was able 
to run it from inside the build directory (with gems disabled). I ran it 
on the same test file that I uploaded for the original issue. This time, 
all 8 lines of code with string literals generated the warning.

sh> ./ruby --disable-gems  bb.rb
bb.rb:21: warning: string literal in condition
bb.rb:22: warning: string literal in condition
bb.rb:23: warning: string literal in condition
bb.rb:24: warning: string literal in condition
bb.rb:25: warning: string literal in condition
bb.rb:26: warning: string literal in condition
bb.rb:27: warning: string literal in condition
bb.rb:28: warning: string literal in condition
["!!false", false]
["!!(false)", false]
["!!nil", false]
["!!(nil)", false]
["!!true", true]
["!!(true)", true]
["!![]", true]
["!!([])", true]
["!!{}", true]
["!!Object.new", true]
["!!(Object.new)", true]
["!!1", true]
["!!(1)", true]
["!!0.1", true]
["!!(0.1)", true]
["!!:a", true]
["!!(:a)", true]
["!!({})", true]
["!!String.new", true]
["!!(String.new)", true]
["!!\"\"", true]
["!!(\"\")", true]
["!!\"b\"", true]
["!!(\"b\")", true]
["!!''", true]
["!!('')", true]
["!!'b'", true]
["!!('b')", true]
sh> ./ruby --version
ruby 2.4.0preview2 (2016-09-09 trunk 56129) [x86_64-linux]


On 10/29/2016 01:29 PM, nagachika00@gmail.com wrote:
> Issue #12881 has been updated by Tomoyuki Chikanaga.
>
> Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: REQUIRED
>
> ----------------------------------------
> Bug #12881: Double-bang (!!) raises warning on string literal
> https://bugs.ruby-lang.org/issues/12881#change-61117
>
> * Author: RRRoy BBBean
> * Status: Closed
> * Priority: Normal
> * Assignee:
> * ruby -v: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
> * Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: REQUIRED
> ----------------------------------------
> I use !!x or !!(x) to force x to true or false.
> I just noticed this trick raises a warning with string literals.
> It would be nice if this warning were not raised, since it is sometimes convenient to force some object to true or false.
> I first saw this in irb, but it also happens when running a script from the command line.
> Caveat: Although the output of my sample program suggests that double-quoted strings avoid this warning, it actually happens with !!"hi" as well as !!'hi'
>
> CODE: bb.rb
>    1 p [ '!!false', !!false ]
>    2 p [ '!!(false)', !!(false) ]
>    3 p [ '!!nil', !!nil ]
>    4 p [ '!!(nil)', !!(nil) ]
>    5 p [ '!!true', !!true ]
>    6 p [ '!!(true)', !!(true) ]
>    7 p [ '!![]', !![] ]
>    8 p [ '!!([])', !!([]) ]
>    9 p [ '!!{}', !!{} ]
>   10 p [ '!!Object.new', !!Object.new ]
>   11 p [ '!!(Object.new)', !!(Object.new) ]
>   12 p [ '!!1', !!1 ]
>   13 p [ '!!(1)', !!(1) ]
>   14 p [ '!!0.1', !!0.1 ]
>   15 p [ '!!(0.1)', !!(0.1) ]
>   16 p [ '!!:a', !!:a ]
>   17 p [ '!!(:a)', !!(:a) ]
>   18 p [ '!!({})', !!({}) ]
>   19 p [ '!!String.new', !!String.new ]
>   20 p [ '!!(String.new)', !!(String.new) ]
>   21 p [ '!!""', !!"" ]
>   22 p [ '!!("")', !!("") ]
>   23 p [ '!!"b"', !!"b" ]
>   24 p [ '!!("b")', !!("b") ]
>   25 p [ "!!''", !!'' ]
>   26 p [ "!!('')", !!('') ]
>   27 p [ "!!'b'", !!'b' ]
>   28 p [ "!!('b')", !!('b') ]
>
> OUTPUT
> bb.rb:25: warning: string literal in condition
> bb.rb:26: warning: string literal in condition
> bb.rb:27: warning: string literal in condition
> bb.rb:28: warning: string literal in condition
> ["!!false", false]
> ["!!(false)", false]
> ["!!nil", false]
> ["!!(nil)", false]
> ["!!true", true]
> ["!!(true)", true]
> ["!![]", true]
> ["!!([])", true]
> ["!!{}", true]
> ["!!Object.new", true]
> ["!!(Object.new)", true]
> ["!!1", true]
> ["!!(1)", true]
> ["!!0.1", true]
> ["!!(0.1)", true]
> ["!!:a", true]
> ["!!(:a)", true]
> ["!!({})", true]
> ["!!String.new", true]
> ["!!(String.new)", true]
> ["!!\"\"", true]
> ["!!(\"\")", true]
> ["!!\"b\"", true]
> ["!!(\"b\")", true]
> ["!!''", true]
> ["!!('')", true]
> ["!!'b'", true]
> ["!!('b')", true]
>
> ruby --version
> ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
> I compiled it myself from sources, running on Fedora24 amd64 workstation
>
>
>
>
> ---Files--------------------------------
> bb.rb (685 Bytes)
>
>


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

end of thread, other threads:[~2016-10-29 23:52 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-12881.20161028173953@ruby-lang.org>
2016-10-28 17:39 ` [ruby-core:77801] [Ruby trunk Bug#12881] Double-bang (!!) raises warning on string literal rrroybbbean
2016-10-29 18:29 ` [ruby-core:77811] " nagachika00
2016-10-30  0:23   ` [ruby-core:77815] " RRRoy BBBean

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