0
votes

I'm working on some Go AST code, and the compiler is choking on this line:

var call ast.Expr = ast.CallExpr{Fun: ast.NewIdent("foo"), Args: []ast.Expr{ast.NewIdent("api")}}

The error it's giving me is:

cannot use ast.CallExpr literal (type ast.CallExpr) as type ast.Expr in assignment:

ast.CallExpr does not implement ast.Expr (End method has pointer receiver)

I have no idea what this is saying; according to the documentation, everything looks fine. What do I have to do to make this work?

1
You're missing a &. The Pos and End methods are implemented by *CallExpr - JimB
@JimB Thanks! Can you make that an answer? - Mason Wheeler

1 Answers

1
votes

The Pos and End methods of ast.Expr are implemented by *ast.CallExpr. You need to assign a pointer to call with &.

var call ast.Expr = &ast.CallExpr{Fun: ast.NewIdent("foo"), Args: []ast.Expr{ast.NewIdent("api")}}