Skip to content

dql/reflects: lookup attr support method#2657

Merged
xushiwei merged 2 commits intogoplus:mainfrom
xushiwei:q
Feb 22, 2026
Merged

dql/reflects: lookup attr support method#2657
xushiwei merged 2 commits intogoplus:mainfrom
xushiwei:q

Conversation

@xushiwei
Copy link
Member

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 introduces a significant enhancement to the attribute lookup mechanism within the dql/reflects package. The primary goal is to extend the existing attribute resolution logic to seamlessly incorporate methods, allowing them to be treated as dynamic properties. This change provides greater flexibility in how data structures are queried and accessed, enabling methods to serve as computed attributes. The modifications ensure that the system can intelligently differentiate between fields and methods, and optionally invoke methods to retrieve their results as attribute values, streamlining data access patterns.

Highlights

  • Enhanced Attribute Lookup: The core lookup function has been significantly refactored to support resolving methods as attributes, in addition to struct fields and map entries. This allows for more dynamic data access.
  • New Lookup Modes: Three new constants (lookupNormal, lookupCallMethod, lookupDontCallMethod) were introduced to control the behavior of the lookup function, enabling callers to specify whether methods should be called, merely found, or ignored during attribute resolution.
  • Method Invocation as Attribute Value: When lookupCallMethod is specified, the lookup function can now identify and invoke methods with no arguments and a single return value, treating their return as the attribute's value.
  • Refactored XGo_hasAttr: The XGo_hasAttr method in dql/reflects/reflects.go was updated to delegate its logic to the Node.XGo_hasAttr method, ensuring consistent attribute checking behavior across the Node and NodeSet types.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • dql/reflects/node.go
    • Modified lookup function signature to accept a mode parameter for controlling method resolution behavior.
    • Added lookupNormal, lookupCallMethod, and lookupDontCallMethod constants to define lookup modes.
    • Implemented logic within lookup to find and optionally call methods that match attribute names, if no field is found.
    • Updated calls to lookup in XGo_Elem, XGo_hasAttr, and XGo_Attr__1 to pass the appropriate lookup mode.
  • dql/reflects/reflects.go
    • Updated the call to lookup in yieldElem to use lookupNormal mode.
    • Refactored XGo_hasAttr to delegate its attribute checking logic to the Node.XGo_hasAttr method.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Feb 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.11%. Comparing base (6a4bcb1) to head (2424408).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2657   +/-   ##
=======================================
  Coverage   94.11%   94.11%           
=======================================
  Files          32       32           
  Lines        9968     9968           
=======================================
  Hits         9381     9381           
  Misses        419      419           
  Partials      168      168           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces support for methods as attributes in DQL queries, allowing users to access data through getter-like methods (0 inputs, 1 output) by enhancing the internal lookup function. However, this implementation allows for unintended method execution on reflected Go objects. If a DQL query is constructed using untrusted user input, an attacker can trigger any exported method that takes no arguments and returns a single value, potentially leading to data leakage or unintended side effects. My feedback also focuses on improving type safety for the new lookup modes.

@xgopilot
Copy link

xgopilot bot commented Feb 22, 2026

Review Summary

This PR adds a useful feature allowing method lookup as attributes on struct nodes. The implementation is clean, with a well-designed fast-path that avoids penalizing normal lookups.

Key observations:

  • The refactoring of NodeSet.XGo_hasAttr to delegate to Node.XGo_hasAttr is a good deduplication improvement
  • Methods are correctly looked up on the original value (not dereferenced) to include pointer-receiver methods
  • The lookupNormal short-circuit ensures zero additional cost for the common case

Suggestions:

  • Consider adding panic recovery for mth.Call(nil) to prevent method panics from crashing query evaluation
  • Update doc comments to document that attributes now include qualifying methods
  • Add test coverage for the new method lookup behavior

@xushiwei xushiwei merged commit 21033f0 into goplus:main Feb 22, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant