Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
The original idea behind the AST is to be minimal, in the sense that it only defines the node types, without predicates for each node; mostly because they are not needed. (I agree that this is not true anymore, especially for CommentGroups and Ident, unfortunately).
So, yes, it would be nice if there were a convenience method, but then the question arises, where do we stop? Should there also be a convenience method to test if a FuncType has a "func" or not? And whether a ConstantSpec has a type, etc? It's hard to draw a boundary at that point. Once we have convenience functions, one and the same thing can be computed in two different ways, via the convenience function, or by direct inspection of the node. Which raises yet another question: What's the recommended way? What if code doesn't adhere to it? etc. etc.
The AST does represent the source code almost exactly 1:1, so if there's a "..." in the source, the Ellipsis position is set, otherwise it's not. It does require some knowledge of the syntax, I agree, but that doesn't seem onerous if one is working with the AST. Finally, note that the AST doesn't make a semantic judgement - just because there's a "..." doesn't mean the call is variadic. The "..." here means that the last argument is expected to be a slice that's used with a variadic function, but that may not be the case. So, HasEllipsis() bool would be a better predicate. But there's virtually no difference between HasEllipsis and Ellipsis.IsValid(), so why bother?
I'll say, let's leave this as is. I will make the comment clearer and then close this. Thanks.