Skip to content

Conversation

@demerphq
Copy link
Collaborator

@demerphq demerphq commented Jul 29, 2022

This PR assumes that the commit in #20000 will be merged and includes it for now.

Treat ${0x10} as $16 and allowed under strict, similarly ${0b10000} and ${0o20}. Without strict they would resolve to $16 as well, but would be treated as symbolic references. Since they are constants and since "all digits vars always exist", it doesn't seem necessary to treat them as symbolic references and forbid this usage under use strict.

Prior to this patch ${0x10} would require "no strict refs", with this patch
it is a legal alternative spelling for $16, likewise with ${0b10000},
and explicit octal (eg, with 0o prefix) as well. Note that ${0x010} and
${0b00010000} and similar are also allowed and will both also map to $16.

Since these values are constant it seems reasonable to treat them like
their decimal equivalents. Note that $0x10 does not work as one might
think, it parses as $0 x 10, only ${0x10} is allowed, similarly
$0b10 is forbidden, but ${0b10} is not. Note that $::0x10 and $::0b10
are NOT digits vars equivalent to $16 and $2, but rather $main::0x10
and $main::0b10.
@demerphq demerphq force-pushed the yves/hex_oct_digit_vars branch from 11c1920 to 1753a64 Compare July 30, 2022 07:32
}
if (shift) {
STRLEN len = PL_bufend - s;
I32 flags = PERL_SCAN_SILENT_ILLDIGIT | PERL_SCAN_DISALLOW_PREFIX;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider setting the PERL_SCAN_ALLOW_UJNDERSCORES flag? (to allow things like 0b11_00_1_1)

Comment on lines +10234 to +10235
if (flags & PERL_SCAN_GREATER_THAN_UV_MAX || d+len >= e)
Perl_croak(aTHX_ "%s", ident_too_long);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test for the flags & PERL_SCAN_GREATER_THAN_UV_MAX condition(?)
The error in that case might also be a bit misleading:

$ ./perl -wle 'use strict; print ${0x1ffffffffffffffff};'
Integer overflow in hexadecimal number at -e line 1.
Hexadecimal number > 0xffffffff non-portable at -e line 1.
Identifier too long at -e line 1.

@bram-perl
Copy link

Personally I don't know if I like this/if this change is a good idea;

As noted: $0xA isn't a valid variable but $::0xA is.
Right now: using ${0xA} triggers an error under use strict;
after this PR it no longer will.

But the real question is what did the user intend?
If someone is using $::0xA as var (which I consider a bad idea) then they might expect that ${0xA}1 resolves to the same var. (It doesn't(/never did) but at least before this PR use strict will complain where as now it might (silently) do the wrong things).

Footnotes

  1. in package main

@demerphq
Copy link
Collaborator Author

demerphq commented Aug 1, 2022 via email

@demerphq
Copy link
Collaborator Author

demerphq commented Sep 2, 2022

On second thought... Lets not.

@demerphq demerphq closed this Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants