Skip to content

v1.6.3#2634

Merged
xushiwei merged 191 commits intov1.6from
main
Feb 16, 2026
Merged

v1.6.3#2634
xushiwei merged 191 commits intov1.6from
main

Conversation

@xushiwei
Copy link
Copy Markdown
Member

No description provided.

xushiwei and others added 30 commits January 26, 2026 17:23
XGo_Env: support fileline param (token.Position)
tryFileLine: remote log & add comments
tryFileLine: use relFile of fileName
XGo_Env: remove fileline support
cl/_testgop: map-field-access (#2571)
Map Field Access with Comma‐ok Propagation #2572
doc: tuple in minispec
fix: prevent duplicate XGo_Init calls in embedded types
shouldCallXGoInit refactor
xushiwei and others added 26 commits February 15, 2026 20:31
dql: reflects,golang; encoding: yaml,golang
dql: xgo; encoding: xgo; encoding.Object
Compile range expressions before entering the for-range block scope so
that auto-generated type assertion statements (e.g. _autoGo_1) are
emitted to the correct outer scope instead of the loop body.

Fixes #2629

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: xushiwei <396972+xushiwei@users.noreply.github.com>
Revert the XGo-side workaround (reordering compileExpr before ForRange)
and instead update gogen to v1.21.2-0.20260216045904-8435674ebccf which
properly fixes the scoping issue in ForRange/RangeAssignThen/End.

See goplus/gogen#593

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: xushiwei <396972+xushiwei@users.noreply.github.com>
cl: fix DQL for-range scoping bug with auto-generated type assertions
@xushiwei xushiwei merged commit 408ae7c into v1.6 Feb 16, 2026
22 checks passed
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 16, 2026

Codecov Report

❌ Patch coverage is 98.25073% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.10%. Comparing base (3b177af) to head (b68abc2).
⚠️ Report is 195 commits behind head on v1.6.

Files with missing lines Patch % Lines
parser/parser.go 95.69% 3 Missing and 1 partial ⚠️
cl/classfile.go 90.90% 1 Missing ⚠️
cl/expr.go 99.43% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             v1.6    #2634      +/-   ##
==========================================
+ Coverage   93.96%   94.10%   +0.14%     
==========================================
  Files          34       32       -2     
  Lines        9797     9964     +167     
==========================================
+ Hits         9206     9377     +171     
+ Misses        421      419       -2     
+ Partials      170      168       -2     

☔ 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.

@gemini-code-assist
Copy link
Copy Markdown
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 significantly expands XGo's capabilities by introducing a powerful DOM Query Language (DQL) for querying structured data and enhancing the framework for domain-specific text literals. It includes a major overhaul of the compiler to support these new language constructs, accompanied by extensive documentation and new test cases to ensure a robust and expressive development experience.

Highlights

  • DOM Query Language (DQL) Introduction: A new DOM Query Language (DQL) has been integrated, enabling powerful and intuitive querying of structured data. This includes new AST nodes (AnySelectorExpr, CondExpr) and compiler support for DQL syntax like X.**.Sel (descendant selection) and expr @ cond (conditional filtering).
  • Enhanced Domain-Specific Text Literals: Domain-specific text literals now leverage dedicated dql and encoding packages, providing robust parsing and manipulation for formats like HTML, JSON, XML, CSV, Go, XGo, and YAML. The encoding packages are now consolidated under github.com/goplus/xgo/encoding/.
  • Comprehensive Documentation Updates: Extensive new documentation has been added and existing files updated to cover built-in functions, function calls, closures, map and slice types, string operations, and the new DQL features. This includes new files like doc/builtin.md, doc/fncall.md, doc/map.md, doc/slice.md, doc/string.md, doc/func-closure.md, and doc/struct-vs-tuple.md.
  • Compiler and Parser Refinements: The compiler and parser have undergone significant updates to support the new DQL syntax, improve expression handling (e.g., consistent lhs=1 for value-producing expressions), and refine error reporting for for..in statements. Obsolete typesalias logic has been removed, simplifying type alias handling.
  • New and Updated Test Cases: Numerous new test cases have been introduced to validate the DQL features, various comprehension syntaxes (list, map, select), error wrapping, and other compiler changes, ensuring the stability and correctness of the new functionalities.
  • Dependency and Go Version Update: The project's go.mod and go.sum files have been updated to Go 1.24.0 with toolchain go1.24.2, and new dependencies like github.com/goccy/go-yaml and golang.org/x/net have been added, alongside updates to existing dependencies.

🧠 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
  • .github/codecov.yml
    • Updated coverage paths to include new DQL and encoding packages and removed obsolete paths.
  • .goreleaser.yaml
    • Included new dql and encoding directories in release archives.
  • README.md
    • Updated documentation links to reflect new and expanded feature guides.
    • Improved descriptions for various XGo language features like list/slice, map, lambda, and keyword argument literals.
  • ast/ast.go
    • Clarified comments for SelectorExpr to indicate support for non-simple identifier selectors.
  • ast/ast_xgo.go
    • Added AnySelectorExpr to represent X.**.Sel expressions for descendant selection.
    • Introduced CondExpr to represent expr @ cond conditional expressions.
    • Updated comment for ErrWrapExpr.
  • ast/walk.go
    • Integrated AnySelectorExpr and CondExpr into the AST traversal mechanism.
  • builtin/doc.xgo
    • Revised documentation for Open, Create, Fatal, and Replace functions.
    • Renamed Gop_Enum to XGo_Enum.
  • cl/_testgop/domaintext-html/go.mod
    • Removed file.
  • cl/_testgop/domaintext-html/go.sum
    • Removed file.
  • cl/_testgop/domaintext-html/in.xgo
    • Removed direct import of golang.org/x/net/html.
  • cl/_testgop/domaintext-html/out.go
    • Updated import to github.com/goplus/xgo/encoding/html and adjusted html.Parse to html.New.
  • cl/_testgop/domaintext-json/in.xgo
    • Added example for yaml domain text literal.
  • cl/_testgop/domaintext-json/out.go
    • Included import for github.com/goplus/xgo/encoding/yaml and corresponding code generation.
  • cl/_testgop/domaintext-regexp/out.go
    • Updated import path for regexp encoding package.
  • cl/_testgop/dql1/in.xgo
    • Added new test case for DQL X.**.Sel and X.$attr syntax.
  • cl/_testgop/dql1/out.go
    • Added generated Go code for DQL X.**.Sel and X.$attr test case.
  • cl/_testgop/dql2/in.xgo
    • Added new test case for DQL expr @ cond syntax.
  • cl/_testgop/dql2/out.go
    • Added generated Go code for DQL expr @ cond test case.
  • cl/_testgop/dql3/in.xgo
    • Added new test case for DQL X.*@name@string syntax.
  • cl/_testgop/dql3/out.go
    • Added generated Go code for DQL X.*@name@string test case.
  • cl/_testgop/dql4/in.xgo
    • Added new test case for XML DQL.
  • cl/_testgop/dql4/out.go
    • Added generated Go code for XML DQL test case.
  • cl/_testgop/dql5/in.xgo
    • Added new test case for HTML DQL.
  • cl/_testgop/dql5/out.go
    • Added generated Go code for HTML DQL test case.
  • cl/_testgop/dql6/in.xgo
    • Added new test case for Go DQL.
  • cl/_testgop/dql6/out.go
    • Added generated Go code for Go DQL test case.
  • cl/_testgop/dql7/in.xgo
    • Added new test case for JSON DQL.
  • cl/_testgop/dql7/out.go
    • Added generated Go code for JSON DQL test case.
  • cl/_testgop/errwrap3/in.xgo
    • Added new test case for error wrapping.
  • cl/_testgop/errwrap3/out.go
    • Added generated Go code for error wrapping test case.
  • cl/_testgop/for-in/in.xgo
    • Added new test case for for in loop syntax.
  • cl/_testgop/for-in/out.go
    • Added generated Go code for for in loop test case.
  • cl/_testgop/for-range/in.xgo
    • Added new test cases for for range loop syntax.
  • cl/_testgop/for-range/out.go
    • Added generated Go code for for range loop test cases.
  • cl/_testgop/list-compr1/in.xgo
    • Added new test case for list comprehension.
  • cl/_testgop/list-compr1/out.go
    • Added generated Go code for list comprehension test case.
  • cl/_testgop/list-compr2/in.xgo
    • Added new test case for multi-level list comprehension.
  • cl/_testgop/list-compr2/out.go
    • Added generated Go code for multi-level list comprehension test case.
  • cl/_testgop/map-compr-cond1/in.xgo
    • Added new test case for map comprehension with condition.
  • cl/_testgop/map-compr-cond1/out.go
    • Added generated Go code for map comprehension with condition test case.
  • cl/_testgop/map-compr-cond2/in.xgo
    • Added new test case for map comprehension with condition and assignment.
  • cl/_testgop/map-compr-cond2/out.go
    • Added generated Go code for map comprehension with condition and assignment test case.
  • cl/_testgop/map-compr1/in.xgo
    • Added new test case for map comprehension.
  • cl/_testgop/map-compr1/out.go
    • Added generated Go code for map comprehension test case.
  • cl/_testgop/map-field-access1/in.xgo
    • Added new test case for map field access.
  • cl/_testgop/map-field-access1/out.go
    • Added generated Go code for map field access test case.
  • cl/_testgop/map-field-access2/in.xgo
    • Added new test case for map field access on any type.
  • cl/_testgop/map-field-access2/out.go
    • Added generated Go code for map field access on any type test case.
  • cl/_testgop/select-compr-twovalue1/in.xgo
    • Added new test case for select comprehension with two-value return.
  • cl/_testgop/select-compr-twovalue1/out.go
    • Added generated Go code for select comprehension two-value return test case.
  • cl/_testgop/select-compr-twovalue2/in.xgo
    • Added new test case for select comprehension with two-value return in a function.
  • cl/_testgop/select-compr-twovalue2/out.go
    • Added generated Go code for select comprehension two-value return in function test case.
  • cl/_testgop/select-compr1/in.xgo
    • Added new test case for select comprehension.
  • cl/_testgop/select-compr1/out.go
    • Added generated Go code for select comprehension test case.
  • cl/_testspx/gshself/demo.gsh
    • Added new test case for gsh self-referencing.
  • cl/_testspx/gshself/out.go
    • Added generated Go code for gsh self-referencing test case.
  • cl/_testspx/xgoinit_dup/Spr_spx.gox
    • Added new test case for sprite initialization.
  • cl/_testspx/xgoinit_dup/main_spx.gox
    • Added new test case for main sprite initialization.
  • cl/_testspx/xgoinit_dup/out.go
    • Added generated Go code for sprite initialization test case.
  • cl/builtin.go
    • Removed cl/internal/typesalias import and associated logic.
    • Updated PkgPathIox to PkgPathOsx in configuration.
  • cl/builtin_test.go
    • Adjusted compileErrWrapExpr call to include the lhs parameter.
  • cl/classfile.go
    • Updated MemberVal calls to correctly pass the lhs parameter.
    • Introduced findMethodByType helper for method lookup.
  • cl/cltest/cltest.go
    • Removed several Go standard library imports and helper functions related to Go version and type alias detection, simplifying the test utility.
  • cl/compile.go
    • Removed cl/internal/typesalias import and related type alias support flags.
    • Updated PkgPathIox to PkgPathOsx for consistency.
    • Modified types.NewAlias usage to align with updated Go types package.
    • Adjusted compileExpr and related functions to consistently use lhs=1 for value-producing expressions.
    • Implemented compileAnySelectorExpr and compileCondExpr for new DQL AST nodes.
    • Refactored compileSelectorExpr to support DQL syntax for element and attribute access.
    • Added compileAttr and unquote helper functions for DQL attribute handling.
    • Updated compileErrWrapExpr to correctly handle the lhs parameter for error wrapping expressions.
    • Introduced shouldCallXGoInit helper to determine if XGo_Init should be called on a receiver type.
  • cl/compile_spx_test.go
    • Updated expected error message for a specific TestSpxErrorEnv scenario.
    • Added a new TestSpxErrorEnv test case.
  • cl/compile_test.go
    • Removed gotypesalias and go1point variables and their associated conditional logic.
    • Updated for loop conditions in TestForPhrase and TestExistsComprehension to use the if keyword.
    • Removed several test cases related to map and select comprehensions, as well as list comprehensions, which are now covered by new dedicated test files.
  • cl/compile_xgo_test.go
    • Simplified TestOverloadNamed and TestMixedOverloadNamed by removing conditional expected output strings, streamlining test logic.
  • cl/error_msg_test.go
    • Added TestErrCondExpr to verify error messages for invalid conditional expressions.
    • Expanded TestErrMember with new error cases for DQL-related member access syntax.
  • cl/expr.go
    • Updated compileIdent to pass the lhs parameter to compileMember.
    • Modified compileEnvExpr to support self.$attr syntax and correctly handle the lhs parameter.
    • Adjusted xgoOp to pass the lhs parameter to Member calls.
    • Updated compileMember to include the lhs parameter.
    • Ensured compileExpr calls consistently use lhs=1 for value-producing expressions.
    • Implemented compileAnySelectorExpr and compileCondExpr for DQL processing.
    • Introduced convMapToNodeSet to convert map types to NodeSet for DQL operations.
    • Added compileAttr and unquote helper functions for DQL attribute handling.
    • Updated compileCallExpr and compileErrWrapExpr to correctly handle the lhs parameter.
    • Refactored domain text literal path resolution to use encodingPkgPrefix.
  • cl/func_type_and_var.go
    • Updated compileExpr call to consistently use lhs=1.
  • cl/internal/dql/dql.go
    • Added new file defining core DQL types (Node, NodeSet) and utility functions (New, NodeSet_Cast, XGo_Enum, XGo_Any, XGo_Select, XGo_Child, XGo_first, XGo_Elem, XGo_Attr__0, XGo_Attr__1, NodeSet2, New2, NodeSet2_Cast, XGo_first, XGo_Enum, XGo_Elem, XGo_Attr).
  • cl/internal/typesalias/alias_go121.go
    • Removed file, simplifying type alias handling.
  • cl/internal/typesalias/alias_go122.go
    • Removed file, simplifying type alias handling.
  • cl/internal/typesalias/typeparams_go122.go
    • Removed file, simplifying type alias handling.
  • cl/internal/typesalias/typeparams_go123.go
    • Removed file, simplifying type alias handling.
  • cl/stmt.go
    • Updated compileExpr calls to consistently use lhs=1.
    • Removed an unnecessary compileExpr call from compileRangeStmt.
  • cl/typeparams.go
    • Removed cl/internal/typesalias import.
    • Updated references from typesalias.Alias to types.Alias and typesalias.Unalias to types.Unalias.
  • cl/typeparams_test.go
    • Simplified TestTypeParamsType, TestTypeParamsErrInferFunc, and TestAliasTypeparams by removing conditional expected output strings and gotypesalias checks.
  • cmd/chore/xgobuiltingen/reference.gox
    • Removed iox from the builtin map.
  • cmd/make.go
    • Removed goVersion function and associated logic for go.work file creation, streamlining the build process.
  • cmd/xgo/xgo_autogen.go
    • Removed extraneous empty lines.
  • demo/domaintext/domaintext.xgo
    • Added new demonstration file for JSON domain text literals.
  • demo/dql-json/jq.xgo
    • Added new demonstration file for JSON DQL queries.
  • demo/dql-links/links.xgo
    • Added new demonstration file for HTML DQL queries.
  • demo/dql-xgo/xgoq.xgo
    • Added new demonstration file for XGo DQL queries.
  • demo/tupletype/tuple.xgo
    • Added example demonstrating the use of maps with tuple keys.
  • doc/builtin.md
    • Added new documentation file detailing XGo's built-in functions and method syntax.
  • doc/docs.md
    • Expanded documentation for map literals and operations.
    • Updated and expanded the section on domain-specific text literals.
  • doc/domian-text-lit.md
    • Rewritten and expanded documentation for domain-specific text literals, covering design, benefits, built-in formats, implementation, custom formats, best practices, and error handling.
  • doc/fncall.md
    • Added new documentation file explaining commands and function calls.
  • doc/func-closure.md
    • Added new documentation file detailing functions and closures.
  • doc/map.md
    • Added new documentation file describing the map type and its operations.
  • doc/slice.md
    • Added new documentation file describing the slice type and its operations.
  • doc/string.md
    • Added new documentation file describing the string type and its operations.
  • doc/struct-vs-tuple.md
    • Added new documentation file comparing tuples and structs.
  • dql/README.md
    • Added new README file for the dql package.
  • dql/dql.go
    • Added new file defining core DQL utilities like NopIter, First, Single, Collect, and Int.
  • dql/fetcher/fetch.go
    • Added new file providing DQL fetcher utilities for data retrieval and conversion.
  • dql/fetcher/github.com/issueTask/issueTask.xgo
    • Added new file with a DQL fetcher example for GitHub issue tasks.
  • dql/fetcher/github.com/repoList/repoList.xgo
    • Added new file with a DQL fetcher example for GitHub repository lists.
  • dql/fetcher/hrefs/hrefs.xgo
    • Added new file with a DQL fetcher example for extracting hrefs from HTML.
  • dql/fetcher/pkg.go.dev/importedBy/importedBy.xgo
    • Added new file with a DQL fetcher example for pkg.go.dev importedBy data.
  • dql/fetcher/pytorch.org/fndoc/fndoc.xgo
    • Added new file with a DQL fetcher example for PyTorch function documentation.
  • dql/golang/golang.go
    • Added new file implementing DQL NodeSet for Go ASTs.
  • dql/golang/parse.go
    • Added new file for parsing Go AST files within DQL.
  • dql/html/html.go
    • Added new file implementing DQL NodeSet for HTML DOM.
  • dql/html/parse.go
    • Added new file for parsing HTML files within DQL.
  • dql/json/json.go
    • Added new file implementing DQL NodeSet for JSON data.
  • dql/maps/maps.go
    • Added new file implementing DQL NodeSet for generic map/slice data structures.
  • dql/reflects/reflects.go
    • Added new file providing DQL reflection utilities.
  • dql/xgo/parse.go
    • Added new file for parsing XGo AST files within DQL.
  • dql/xgo/xgo.go
    • Added new file implementing DQL NodeSet for XGo ASTs.
  • dql/xml/parse.go
    • Added new file for parsing XML nodes within DQL.
  • dql/xml/xml.go
    • Added new file implementing DQL NodeSet for XML DOM.
  • dql/yaml/yaml.go
    • Added new file implementing DQL NodeSet for YAML data.
  • encoding/csv/csv.go
    • Renamed from tpl/encoding/csv/csv.go.
    • Updated Object type alias and New function comment for clarity.
  • encoding/golang/golang.go
    • Added new file for Go domain text literal support.
  • encoding/html/html.go
    • Added new file for HTML domain text literal support.
  • encoding/json/json.go
    • Renamed from tpl/encoding/json/json.go.
    • Updated Object type alias and New function comment for clarity.
  • encoding/regexp/regexp.go
    • Renamed from tpl/encoding/regexp/regexp.go.
    • Updated Object type alias and New function comment for clarity.
  • encoding/regexposix/regexp.go
    • Renamed from tpl/encoding/regexposix/regexp.go.
    • Updated Object type alias and New function comment for clarity.
  • encoding/xgo/xgo.go
    • Added new file for XGo domain text literal support.
  • encoding/xml/xml.go
    • Renamed from tpl/encoding/xml/xml.go.
    • Updated Object type alias and New function comment for clarity.
  • encoding/yaml/yaml.go
    • Added new file for YAML domain text literal support.
  • go.mod
    • Updated Go version to 1.24.0 and added toolchain go1.24.2.
    • Added new dependencies github.com/goccy/go-yaml and golang.org/x/net.
    • Updated existing dependencies github.com/goplus/gogen and github.com/goplus/mod.
  • go.sum
    • Updated checksums for all modified and new dependencies.
  • parser/_testdata/dql1/dql.xgo
    • Added new parser test data for DQL syntax.
  • parser/_testdata/dql1/parser.expect
    • Added expected parser output for DQL syntax test data.
  • parser/_testdata/dql2/dql.xgo
    • Added new parser test data for DQL syntax.
  • parser/_testdata/dql2/parser.expect
    • Added expected parser output for DQL syntax test data.
  • parser/_testdata/mytest/mytest.xgo
    • Applied formatting to os.FileInfo and os.Open calls.
  • parser/iox/io.go
    • Added detailed comments for ReadSource and ReadSourceLocal functions.
  • parser/parser.go
    • Implemented parsing logic for new AnySelectorExpr and CondExpr AST nodes.
    • Updated error messages for for..in statements to be more descriptive.
    • Refined parsing of selectors to support DQL-specific syntax like .** and .$.
  • parser/parser_test.go
    • Added TestErrCondExpr to verify error handling for conditional expressions.
    • Expanded TestErrSelectorExpr with new error cases for DQL-related selector syntax.
  • printer/nodes.go
    • Integrated AnySelectorExpr and CondExpr into the code printer for correct formatting.
  • printer/printer.go
    • Updated comment for commentedStmts to reflect XGo context.
  • scanner/scanner.go
    • Introduced new tokens TILDE and AT for expanded language features.
  • token/token.go
    • Added AT token and removed POW token.
    • Adjusted additional_end and IsOperator logic to reflect token changes.
  • token/token_test.go
    • Updated TestArrowOp to include SRARROW and AT tokens and adjusted expected token count.
  • tpl/scanner/_testdata/pow/tpl.expect
    • Removed ** token from expected output.
  • tpl/scanner/scanner.go
    • Removed POW token and its associated scanning logic.
  • tpl/token/token.go
    • Removed POW token definition.
  • tpl/token/token_test.go
    • Adjusted expected token count in tests.
  • x/typesutil/info_test.go
    • Removed cltest import and gotypesalias variable.
    • Simplified TestOverloadNamed and TestMixedOverloadNamed by removing conditional expected output strings.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/go.yml
Activity
  • The pull request was created by xushiwei, indicating a new version release or release candidate.
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.

Copy link
Copy Markdown
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

This is a very impressive pull request that introduces the powerful Data Query Language (DQL) feature, along with a major refactoring of encoding packages and a significant documentation effort. The DQL implementation is well-designed and extensible, providing a unified query interface for various data formats like JSON, XML, HTML, and even Go/XGo source code. The cleanup of the typesalias workaround and the bump to Go 1.24 are also welcome modernizations. I've found a couple of potential issues in the new DQL compiler logic that need attention, but overall, this is a fantastic contribution.

}

func compileAnySelectorExpr(ctx *blockCtx, lhs int, v *ast.AnySelectorExpr) {
compileExpr(ctx, 0, v.X)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

It seems there's a potential bug here. The lhs argument to compileExpr is 0, which typically means the expression's result is discarded. However, the subsequent call to convMapToNodeSet (and its underlying call to cb.Get(-1)) expects the result of v.X to be on the stack. This will likely lead to a compiler panic or incorrect code generation.

Other similar functions in this file, like compileSelectorExpr and compileCondExpr, use compileExpr(ctx, 1, ...) to ensure the result is available. This should probably be compileExpr(ctx, 1, v.X) as well.

Suggested change
compileExpr(ctx, 0, v.X)
compileExpr(ctx, 1, v.X)

Comment on lines +536 to +541
If().DefineVarStart(0, nameVal, nameErr).
Val(varSelf).MemberVal("XGo_first", 0, v).CallWith(0, 2, 0, v)
firstRet := cb.Get(-1)
nodeType := firstRet.Type.(*types.Tuple).At(0).Type()
varYield := newNodeSeqParam(pkgTypes, nodeType)
cb.EndInit(1).VarVal(nameErr).Val(nil).BinaryOp(gotoken.EQL).Then().
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The logic here hardcodes the assumption that the XGo_first method returns two values (a node and an error), by using CallWith(0, 2, ...) and DefineVarStart(0, nameVal, nameErr).

This assumption doesn't hold for all NodeSet implementations. For example, the TestErrCondExpr test case uses a NodeSet2 whose XGo_first method returns only a single value, causing a compilation error.

To make this more robust, the compiler should inspect the signature of XGo_first. Based on the number of return values, it should generate different code for variable assignment and error handling.

  • If XGo_first returns two values, the current logic is correct.
  • If XGo_first returns one value, it should be assigned directly to _xgo_val, and the error handling block should be skipped.

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.

4 participants