-
Notifications
You must be signed in to change notification settings - Fork 560
xgo/ast: add Kwargs []*KwargExpr for CallExpr #2444
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
Conversation
Summary of ChangesHello @xushiwei, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the Abstract Syntax Tree (AST) for function call expressions by relocating the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request refactors the CallExpr AST node by moving it from ast/ast.go to ast/ast_gop.go and extends it to support keyword arguments. This is achieved by adding a Kwargs field to CallExpr and introducing a new KwargExpr node type. The changes are well-structured and consistent with the existing codebase. My only suggestion is to update the documentation for CallExpr to reflect its new capability.
|
|
||
| // ----------------------------------------------------------------------------- | ||
|
|
||
| // A CallExpr node represents an expression followed by an argument list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment for CallExpr is no longer fully accurate with the addition of keyword arguments. It would be clearer to mention that the argument list can now include both positional and keyword arguments.
| // A CallExpr node represents an expression followed by an argument list. | |
| // A CallExpr node represents an expression followed by an argument list, which may include positional and keyword arguments. |
Code Review SummaryGood work adding keyword argument support! Found critical issues requiring fixes: Security: Nil pointer panics in Pos()/End() methods, missing AST walker updates Details in inline comments below. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical Issues
ast/ast_gop.go:92-95 - Missing Position Field
Critical: KwargExpr missing separator position field. Following the KeyValueExpr pattern (ast/ast.go:269-273), should include:
type KwargExpr struct {
Name *Ident // argument name
Sep token.Pos // position of "=" or ":"
Value Expr // argument value
}This is essential for error reporting, formatting tools, and IDE features.
ast/ast_gop.go:74 - Nil Pointer Risk
Security: Nil pointer panic if Fun is nil. Add nil check:
func (x *CallExpr) Pos() token.Pos {
if x.Fun != nil {
return x.Fun.Pos()
}
return x.Lparen
}ast/ast_gop.go:97 - Nil Pointer Risk
Security: Nil pointer panic if Name is nil. Add nil check:
func (x *KwargExpr) Pos() token.Pos {
if x.Name != nil {
return x.Name.Pos()
}
if x.Value != nil {
return x.Value.Pos()
}
return token.NoPos
}ast/ast_gop.go:101 - Nil Pointer Risk
Security: Nil pointer panic if Value is nil. Add nil check:
func (x *KwargExpr) End() token.Pos {
if x.Value != nil {
return x.Value.End()
}
if x.Name != nil {
return x.Name.End()
}
return token.NoPos
}ast/walk.go - Missing AST Walker Updates
Security: The Walk function doesn't traverse Kwargs field or handle KwargExpr nodes. This causes security analysis tools to miss code in keyword arguments. Need to:
- Update
CallExprcase to walkKwargs:
case *CallExpr:
Walk(v, n.Fun)
walkList(v, n.Args)
walkList(v, n.Kwargs) // Add this- Add
KwargExprcase:
case *KwargExpr:
Walk(v, n.Name)
Walk(v, n.Value)Style Issues
ast/ast_gop.go:97,101,105 - Inconsistent Receiver Naming
Expression nodes use x as receiver, not p. Update KwargExpr methods to use x.
ast/ast_gop.go:62 - Documentation Update
Update CallExpr comment to mention keyword arguments:
// A CallExpr node represents an expression followed by an argument list.
// The argument list may include positional arguments (Args) and/or
// keyword arguments (Kwargs).ast/ast_gop.go:97,101 - Missing Method Documentation
Add documentation comments for Pos() and End() methods following the pattern used elsewhere in the file.
Documentation Gap
This adds a new language feature (keyword arguments) but there are no:
- Syntax examples in code comments
- Updates to language specification files
- Usage examples showing the kwarg syntax
Consider adding examples showing the actual syntax (e.g., func(arg: value) or func(arg=value)).
#2443