Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion fail when returning an anonymous function. #14

Open
quanyang opened this issue Mar 15, 2016 · 6 comments
Open

Assertion fail when returning an anonymous function. #14

quanyang opened this issue Mar 15, 2016 · 6 comments

Comments

@quanyang
Copy link

In the following code example, an anonymous function is returned, acting like a closure. However, the Printer class expects a function name.

function generateComparisonFunctionForKey($key) {
        return function ($left, $right) use ($key) {
            if ($left[$key] == $right[$key])
                return 0;
            else
                return ($left[$key] < $right[$key]) ? -1 : 1;
        };
    }

Error:

Warning: assert(): Assertion failed in /Users/<redacted>/php-cfg/lib/PHPCfg/Printer.php on line 46
@nikic
Copy link
Collaborator

nikic commented Mar 15, 2016

The assertion error is fixed by d43ed9f.

However the way we handle bound closure variables currently is not good (and for the reference case outright violates SSA). Closure body also shouldn't be part of the same CFG really...

@quanyang
Copy link
Author

Yea, seems like an issue I'll face later.

@nikic
Copy link
Collaborator

nikic commented Mar 15, 2016

Follow-up fix: 8e85ad3

I didn't have notices enabled locally, so missed that part.

@nikic
Copy link
Collaborator

nikic commented Mar 22, 2016

In 0d54187 I've introduced a Func structure, so each function has a clearly separated CFG. The Funcs are collected in a Script, which is what is returned by the parser now.

Closures still need extra work for the use variable handling.

@quanyang
Copy link
Author

Does GraphViz still work?

@nikic
Copy link
Collaborator

nikic commented Mar 28, 2016

GraphViz printer fixed in 1b0e384. Also added a printScript method to print all functions into one graph.

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

No branches or pull requests

2 participants