# New Ticket Created by Roger Browne # Please include the string: [perl #38174] # in the subject line of all future correspondence about this issue. # <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=38174 >
Currently, there's an error in the way that parrot's string to integer conversion handles multiple '-' and '+' characters. For example, this PIR code... .sub 'main' :main set $S0, '--4' set $I0, $S0 print $I0 print "\n" .end ...erroneously prints -4. Attached is a patch that modifies src/string.c so that string_to_int looks only for digits after seeing the first occurrence of '-' or '+'. The patch also extends t/op/types.t to test this and similar cases. Regards, Roger Browne
Index: src/string.c =================================================================== --- src/string.c (revision 10937) +++ src/string.c (working copy) @@ -1928,8 +1928,12 @@ /* we've not yet seen any digits */ if (c == '-') { sign = -1; + in_number = 1; } - else if (c == '+' || isspace(c)) + else if (c == '+') { + in_number = 1; + } + else if (isspace(c)) ; else break; Index: t/op/string.t =================================================================== --- t/op/string.t (revision 10937) +++ t/op/string.t (working copy) @@ -1631,6 +1631,66 @@ print I0 print "\n" + set S0, "+" + set I0, S0 + print I0 + print "\n" + + set S0, "++" + set I0, S0 + print I0 + print "\n" + + set S0, "+2" + set I0, S0 + print I0 + print "\n" + + set S0, " +3" + set I0, S0 + print I0 + print "\n" + + set S0, "++4" + set I0, S0 + print I0 + print "\n" + + set S0, "+ 5" + set I0, S0 + print I0 + print "\n" + + set S0, "-" + set I0, S0 + print I0 + print "\n" + + set S0, "--56" + set I0, S0 + print I0 + print "\n" + + set S0, " -+67" + set I0, S0 + print I0 + print "\n" + + set S0, " +-78" + set I0, S0 + print I0 + print "\n" + + set S0, " -089xyz" + set I0, S0 + print I0 + print "\n" + + set S0, "- 89" + set I0, S0 + print I0 + print "\n" + end CODE 123 @@ -1638,6 +1698,18 @@ -1 0 0 +0 +0 +2 +3 +0 +0 +0 +0 +0 +0 +-89 +0 OUTPUT