Php-parser: invalid ast for `silent`

Created on 18 Jan 2019  路  9Comments  路  Source: glayzzle/php-parser

Input:

$var = @foo() || @foo();

silent node should be before call, now it is before bin

Right output from php parser:

array(
    0: Stmt_Expression(
        expr: Expr_Assign(
            var: Expr_Variable(
                name: var
            )
            expr: Expr_BinaryOp_BooleanOr(
                left: Expr_ErrorSuppress(
                    expr: Expr_FuncCall(
                        name: Name(
                            parts: array(
                                0: foo
                            )
                        )
                        args: array(
                        )
                    )
                )
                right: Expr_ErrorSuppress(
                    expr: Expr_FuncCall(
                        name: Name(
                            parts: array(
                                0: foo
                            )
                        )
                        args: array(
                        )
                    )
                )
            )
        )
    )
)

But

$var = @(foo() || foo());

Output valid ast.

Very high priority.

bug AST high-pri

Most helpful comment

Hi @evilebottnawi,

$> ping ichiriac
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.

--- 127.0.0.1 ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 12days

Sorry dude, had a lot of work to finish, I'm back on the project this week

All 9 comments

Same problem for

@$i / 0;
@($i / 0);

It's about node precedence, I'll take a look

i've started a fix on this, it resolves your case but may not work on other nodes like retif, cast or propertylookup - needs more tests but didn't had enough time.

I'll be back next week :hand:

@ichiriac thanks for amazing work, it is really help to improve our prettier plugin for PHP, we try to update to latest commit and check on regressions

/cc @ichiriac friendly ping, can we solve some high priority issues (include this)? :smile:

/cc @ichiriac friendly ping again :disappointed: We need help with this

Hi @evilebottnawi,

$> ping ichiriac
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.

--- 127.0.0.1 ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 12days

Sorry dude, had a lot of work to finish, I'm back on the project this week

I have some time this summer to fix some issues.

This bug is ready to release unless I'm missing some test. Here my tests :

  it("test silent node / bin", function() {
    shouldBeSame("@foo() || @foo();", "(@foo()) || (@foo());");
  });
  it("test silent node / div", function() {
    shouldBeSame("@$i / 0;", "@($i) / 0;");
  });
  it("test silent node / ret if", function() {
    shouldBeSame("@$i == true ? @$foo : @$bar;", "@($i) == true ? @($foo) : @($bar);");
  });
  it("test silent node / cast", function() {
    shouldBeSame("@(int)$i + 1;", "@((int)$i) + 1;");
  });
  it("test silent node / property lookup", function() {
    shouldBeSame("@$foo->bar;", "@($foo)->bar;");
  });

Will be great if we fix some major bugs

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mgrip picture mgrip  路  3Comments

ichiriac picture ichiriac  路  7Comments

Rivendall picture Rivendall  路  6Comments

alexander-akait picture alexander-akait  路  3Comments

DaGhostman picture DaGhostman  路  6Comments