New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't overload numeric constant 0. #6870
Comments
From @AbigailCreated by @AbigailThe following program overloads numeric constants, and should turn #!/usr/bin/perl use strict; BEGIN { BEGIN {print "print 0;\n"} BEGIN {print "print 1;\n"} __END__ It doesn't modify 0 though. I would have expected the result to be: print 0; Perl Info
|
From rick@bort.caOn Mon, Oct 27, 2003 at 01:05:37PM +0100, Abigail wrote: [snip tests] The original bug is "Can't overload numeric constant 0.", specifically -- Inline Patch--- toke.c.orig Mon Oct 27 11:04:56 2003
+++ toke.c Mon Oct 27 12:00:13 2003
@@ -7252,6 +7252,7 @@
UV u = 0;
I32 shift;
bool overflowed = FALSE;
+ bool just_zero = TRUE; /* just plain 0 or binary number? */
static NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
static char* bases[5] = { "", "binary", "", "octal",
"hexadecimal" };
@@ -7268,9 +7269,11 @@
if (s[1] == 'x') {
shift = 4;
s += 2;
+ just_zero = FALSE;
} else if (s[1] == 'b') {
shift = 1;
s += 2;
+ just_zero = FALSE;
}
/* check for a decimal in disguise */
else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
@@ -7342,6 +7345,7 @@
*/
digit:
+ just_zero = FALSE;
if (!overflowed) {
x = u << shift; /* make room for the digit */
@@ -7400,7 +7404,10 @@
#endif
sv_setuv(sv, u);
}
- if (PL_hints & HINT_NEW_BINARY)
+ if (just_zero && (PL_hints & HINT_NEW_INTEGER))
+ sv = new_constant(start, s - start, "integer",
+ sv, Nullsv, NULL);
+ else if (PL_hints & HINT_NEW_BINARY)
sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL);
}
break; |
From @rgarciaRick Delaney wrote:
Thanks, applied as #21566, with Abigail's deTODOified tests.
|
@rgs - Status changed from 'new' to 'resolved' |
Migrated from rt.perl.org#24313 (status was 'resolved')
Searchable as RT24313$
The text was updated successfully, but these errors were encountered: