diff --git a/pkg/visitor/formatter/formatter.go b/pkg/visitor/formatter/formatter.go index c82a741..beaedea 100644 --- a/pkg/visitor/formatter/formatter.go +++ b/pkg/visitor/formatter/formatter.go @@ -226,7 +226,9 @@ func (formatter *formatter) Argument(node *ast.Argument) { node.AmpersandTkn = formatter.newToken('&', []byte("&")) } - node.Expr.Accept(formatter) + if node.Expr != nil { + node.Expr.Accept(formatter) + } } func (formatter *formatter) Attribute(node *ast.Attribute) { diff --git a/pkg/visitor/formatter/formatter_test.go b/pkg/visitor/formatter/formatter_test.go index 6e501bb..e100815 100644 --- a/pkg/visitor/formatter/formatter_test.go +++ b/pkg/visitor/formatter/formatter_test.go @@ -3863,6 +3863,38 @@ func TestFormatter_ExprFunctionCall(test *testing.T) { } } +func TestFormatter_ExprFunctionCall_FirstClassCallable(test *testing.T) { + buffer := bytes.NewBufferString("") + + node := &ast.ExprFunctionCall{ + Function: &ast.Name{ + Parts: []ast.Vertex{ + &ast.NamePart{ + Value: []byte("foo"), + }, + }, + }, + Args: []ast.Vertex{ + &ast.Argument{ + VariadicTkn: &token.Token{}, + }, + }, + } + + formatterValue := formatter.NewFormatter().WithState(formatter.FormatterStatePHP).WithIndent(1) + node.Accept(formatterValue) + + printerValue := printer.NewPrinter(buffer).WithState(printer.PrinterStatePHP) + node.Accept(printerValue) + + expected := `foo(...)` + actual := buffer.String() + + if expected != actual { + test.Errorf("\nexpected: %s\ngot: %s\n", expected, actual) + } +} + func TestFormatter_ExprFunctionCall_Arguments(test *testing.T) { buffer := bytes.NewBufferString("")