xp-framework / compiler

Compiles future PHP to today's PHP.
19 stars 0 forks source link

Lambda parameters bleeding into locals #176

Closed thekid closed 1 year ago

thekid commented 1 year ago

Given the following code:

$nonNull= fn($record) => null !== $record;
$process= fn($records, $filter) => {
  foreach ($records as $record) {
    if ($filter($record)) yield $record;
  }        
};

When run, this yields:

Unexpected exception lang.NullPointerException (Undefined variable $record)

The problem is that the second lambda is emitted as a function with use($record), caused by the first lambda's first parameter bleeding into the scope's locals.