snoopyjc / pythonizer

Automatic translator from Perl to Python
https://snoopyjc.org/pythonizer/
Artistic License 2.0
12 stars 1 forks source link

Nested anonymous sub that contains a while loop with an array assignment can generate bad code #322

Closed snoopyjc closed 1 year ago

snoopyjc commented 1 year ago

Nested anonymous sub that contains a while loop with an array assignment can generate bad code. For example (from DBI.pm):

my $connect_closure = sub {
    ...
    if(%$apply) {
        ...
        while ( my ($a, $v) = each %$apply) {
            eval { $dbh->{$a} = $v }; # assign in void context to avoid re-FETCH
            warn $@ if $@;
    }
    }                          # Pythonizer thinks the anonymous sub ends here
...
};
snoopyjc commented 1 year ago

Fixed in 1.029