Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Simple boolean test is fail with empty string in for loop when IntegerFast mode.



  • Please log in to reply
5 replies to this topic
inode817
  • Members
  • 3 posts
  • Last active: Oct 05 2014 05:19 AM
  • Joined: 27 Jan 2013

I was wrote simple test script. but, this will shows message box "2 is True".
But, I am expected to never display this message box.
Because the empty string is not 'true' value.
If you change the lines marked 'ok' in script, this script will be work correctly.
 

;SetFormat, IntegerFast, D ; (default)
;SetFormat, Integer, D ; ok
;For i, v in ["", 0] ; ok
For i, v in [0, ""]
{
; If !!v        ; ok
  If v          ; not ok
    MsgBox, % i " is True" ; >> 2 is True
}

 



GeekDude
  • Spam Officer
  • 391 posts
  • Last active: Oct 05 2015 08:13 PM
  • Joined: 23 Nov 2009

o_O


For i, v in [0, "", 3, "e", ""]
{
    msgbox, % i ": " v ; If this line is here
    If v               ; then this works
        MsgBox, % i " is True"
}



nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010

Interesting...



inode817
  • Members
  • 3 posts
  • Last active: Oct 05 2014 05:19 AM
  • Joined: 27 Jan 2013

I think that the Maxwell's demon lives in AHK.



Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
✓  Best Answer
This bug occurs in certain cases where an empty string is assigned to a variable which contains an unflushed binary number and has zero capacity. As a side-effect of the assignment, the binary number is flushed and although the value is overwritten by the assignment, the length of the previous value is used in place of the length (0) of the new value (an empty string). Because the length is non-zero and the value is not an integer, the value is considered true.

An expression like i ": " v causes the cached binary number to be "flushed"; that is, the variable is updated to contain a string representation of the number in addition to the binary number. In this case, to avoid the bug the expression must be evaluated in the first iteration, while v contains a number.

While trying to simplify the code to reproduce this bug, I found a related bug. This one can be reproduced in v1.0.48.05 and later (and a few versions earlier):
s := 0+1234
s := zero_capacity_var "!"
MsgBox % s  ; 1234!
Fixes for both bugs will be included in the next release.

inode817
  • Members
  • 3 posts
  • Last active: Oct 05 2014 05:19 AM
  • Joined: 27 Jan 2013

It was felt refreshed.
 

thank you for your work.