nayakgi / perl-compiler

Automatically exported from code.google.com/p/perl-compiler
Other
0 stars 0 forks source link

Subroutines called only in regexes not saved #349

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

> perlcc -r -e 'sub foo { return 42 } my $re = qr/ (.+) (??{ foo $1 }) /x; 
123456 =~ $re; print "ok\n";'Can't call method "foo" without a package or 
object reference at (re_eval 1) line 1.

What is the expected output? 

> perl -e 'sub foo { return 42 } my $re = qr/ (.+) (??{ foo $1 }) /x; 123456 =~ 
$re; print "ok\n";'
ok

Please use labels and text to provide additional information.

using release branch at ff8f39b75

Original issue reported on code.google.com by nicolas....@gmail.com on 19 Jun 2014 at 7:59

GoogleCodeExporter commented 9 years ago
Interesting. I thought only access to lexicals vs globals is still broken. 

Original comment by reini.urban on 20 Jun 2014 at 4:11

GoogleCodeExporter commented 9 years ago
This problem is very similar to the one illustrated in issue 348, except it 
pertains to the saving of CVs.  To wit, in Nicolas' example, calling foo() 
prior to the regex will cause his example to work.  On the other hand, calling 
foo() in an anonymous subroutine that is called prior to the regex will not 
cause his example to work.  Furthermore, this problem manifests in plain 
regexes, not just quoted regexes.

I've attached a few files which illustrate my points more explicitly.

Original comment by erin.schoenhals on 20 Jun 2014 at 6:12

Attachments:

GoogleCodeExporter commented 9 years ago
Apologies: Within a regex, this problem only occurs when passing an argument to 
a function in a function call.  On the other hand, when passing an explicit 
value to a function inside a regex function call, rather than a match variable 
within a regex, perlcc fails in a different manner (which probably warrants a 
different issue):

Number found where operator expected at (re_eval 1) line 1, near "foo 36"
         (Do you need to redeclare foo?)
syntax error at (re_eval 1) line 1, near "foo 36"
Compilation failed in regexp.

Original comment by erin.schoenhals on 20 Jun 2014 at 9:37

GoogleCodeExporter commented 9 years ago
Erin's testcase: 
sub foo {  '42'; }
if ("42 cats" =~ /^(??{foo})/) {
    print "ok\n";
}
#foo();

Original comment by reini.urban on 31 Aug 2014 at 7:28