mauke / Function-Parameters

Function::Parameters - define functions and methods with parameter lists ("subroutine signatures")
https://metacpan.org/pod/Function::Parameters
18 stars 19 forks source link

Internal error in %^H with Sub::Quote and 2.001001 #30

Closed sdt closed 6 years ago

sdt commented 7 years ago

The following code causes an internal error in 2.001001

use Function::Parameters    qw( :strict );
use Sub::Quote              qw( quote_sub );

my $subref = quote_sub 'print "Hello, world!\n"';
$subref->();

The error is

Eval went very, very wrong:

 1: {
 2:   my $_UNQUOTED = ${$_[1]->{"\$_UNQUOTED"}};
 3:   my $_QUOTED = ${$_[1]->{"\$_QUOTED"}};
 4:   package main;
 5:   $$_UNQUOTED = sub {
 6:   ($_QUOTED,$_UNQUOTED) if 0;
 7: # BEGIN quote_sub PRELUDE
 8: package main;
 9: BEGIN {
10:   $^H = 131328;
11:   ${^WARNING_BITS} = undef();
12:   %^H = (
13:     "Function::Parameters/config" => "HASH(0x7fe6e98a9268)",
14:   );
15: }
16: # END quote_sub PRELUDE
17: print "Hello, world!\n"  };
18: }
19: 1;

Function::Parameters: internal error: $^H{'Function::Parameters/config'} not a hashref: HASH(0x7fe6e98a9268) at (eval 6) line 17.
 at test.pl line 5.

The error is not present in 2.000007

If I remove :strict and just have use Function::Parameters qw( ); it works.

mauke commented 7 years ago

This is arguably a bug in Sub::Quote:

use strict;                                                                                                                                 
use warnings;
use Sub::Quote qw( quote_sub );

print "\N{DEGREE SIGN}_\N{DEGREE SIGN}\n";
my $subref = quote_sub 'print "\N{INVERTED EXCLAMATION MARK}Hola, mundo!\n"';
$subref->();

Output:

$ perl try.pl                                                                                                   
°_°                                                                                                                                         
Eval went very, very wrong:                                                                                                                 

 1: {
 2:   my $_QUOTED = ${$_[1]->{"\$_QUOTED"}};
 3:   my $_UNQUOTED = ${$_[1]->{"\$_UNQUOTED"}};
 4:   package main;
 5:   $$_UNQUOTED = sub {
 6:   ($_QUOTED,$_UNQUOTED) if 0;
 7: # BEGIN quote_sub PRELUDE
 8: package main;
 9: BEGIN {
10:   $^H = 133090;
11:   ${^WARNING_BITS} = "UUUUUUUUUUUUUUUU\025";
12:   %^H = (
13:     "charnames" => "CODE(0x91994d0)",
14:     "charnames_inverse_ords" => "HASH(0x91665f0)",
15:     "charnames_stringified_names" => "",
16:     "charnames_loose" => 0,
17:     "charnames_short" => 1,
18:     "charnames_name_aliases" => "HASH(0x9166010)",
19:     "charnames_scripts" => "",
20:     "charnames_stringified_ords" => "",
21:     "charnames_ord_aliases" => "HASH(0x91493b0)",
22:     "charnames_full" => 1,
23:     "charnames_stringified_inverse_ords" => "",
24:   );
25: }
26: # END quote_sub PRELUDE
27: print "\N{INVERTED EXCLAMATION MARK}Hola, mundo!\n"  };
28: }
29: 1;

Undefined subroutine &main::CODE(0x91994d0) called at (eval 6) line 27.
 at try.pl line 7.
mauke commented 7 years ago

Reported as https://rt.cpan.org/Ticket/Display.html?id=122698.

mauke commented 7 years ago

I could put a workaround into Function::Parameters. The effect would be to effectively disable Function::Parameters in quote_sub code. This wouldn't throw an error, but custom keywords wouldn't be available either. Would that be a good thing?

sdt commented 7 years ago

Thanks for looking into this.

Your suggested workaround would work for me, but I can work around this pretty easily, so don't add any hacks just on account of me.

mauke commented 6 years ago

Closing this for now because it's not a bug in Function::Parameters and I don't intend to work on this (unless someone requests it).

mauke commented 1 year ago

The workaround (downgrade the internal error to a warning) is now live in v2.001006 because use re 'eval' has the same issue as Sub::Quote here.