Skip to content

Return go types v2#27

Merged
nitram509 merged 4 commits intomainfrom
go-types
Mar 8, 2026
Merged

Return go types v2#27
nitram509 merged 4 commits intomainfrom
go-types

Conversation

@nitram509
Copy link
Member

@nitram509 nitram509 commented Mar 8, 2026

This PR superseeds #26 from @trojanc with including some minor code fixes after merge.


Original PR description

This PR attempts to address #3 and returns go types with EvalString and EvalStringWithScope

This MR also adds a small fix to have tck tests run

Assumptions made:

  • All lists with be of type []any
  • All maps will be of type map[string]any
  • All numbers will be returned as float64
  • Referencing structs with e.g get value will return the struct being referenced instead of a half baked map (mapstructure does unintended things....)

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 refines the expression evaluation engine by standardizing the return types of FEEL expressions to native Go types, enhancing interoperability and simplifying downstream consumption of results. It also introduces a more flexible mechanism for handling and extracting values from various context structures, improving the overall robustness of context-aware functions. These changes incorporate and build upon previous work, ensuring a more consistent and predictable API.

Highlights

  • Native Go Type Returns: Implemented a new unwrapFEELValue function that converts internal FEEL types (like Number, Date, Time, Duration) into their corresponding native Go types (float64, time.Time, time.Duration, nil) when evaluating expressions. This standardizes the output for better integration.
  • Enhanced Context Handling: Introduced a new utility function getContextMap to flexibly extract values from various input types (maps, structs) into a target map, respecting JSON tags for struct fields. This improves how context values are accessed and processed.
  • Refined get value Function: The get value built-in function was updated to leverage the new getContextMap for more robust and consistent retrieval of values from complex contexts, supporting both single keys and key paths.
  • Comprehensive Test Updates: The test suite, including list functions, temporal expressions, and context access tests, was significantly updated to reflect the new native Go type return values, ensuring correctness and consistency with the changes.

🧠 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
  • builtins.go
    • Reordered import statements for github.com/mitchellh/mapstructure.
    • Added a new getContextMap function to extract values from maps or structs into a target map, supporting JSON tags for struct fields.
  • builtins_list_test.go
    • Removed t.Skip directives from various list function tests (count, min, max, sum, sublist, append, concatenate, insert before, remove, reverse, index of, union, distinct values, flatten, product, median).
    • Updated assertions in list function tests to expect native Go types (e.g., float64 for numbers, []any for lists) and added test cases for float64 and mixed-type lists.
  • builtins_misc_test.go
    • Modified the Test_builtin_misc_today_just_returns_a_date test to expect a native time.Time object instead of a custom FEELDate.
  • context.go
    • Refactored the get value built-in function to utilize the new getContextMap for processing the context argument, improving value retrieval logic.
  • eval.go
    • Added reflect package import.
    • Introduced unwrapFEELValue function to recursively convert internal FEEL types to native Go types.
    • Modified EvalStringWithScope to call unwrapFEELValue before returning the evaluation result.
  • eval_test.go
    • Renamed Test_N to Test_float64 and updated assertions to expect float64 instead of custom N type.
    • Updated various test cases to expect float64 for numeric results and time.Time for temporal results.
    • Added a Map map[any]any field to the ScopeObj struct for testing map access.
    • Added new test cases for accessing map fields within ScopeObj and updated existing get value tests to expect nil for null values and float64 for numbers.
  • tests/feel_test_helper.go
    • Added time package import.
    • Modified CreateExpected function to parse expected dateTime, date, decimal/double, and time values into native Go types (time.Time, float64, time.Duration) for consistent testing.
  • tests/tck/tck_test.go
    • Adjusted the condition for processing test.Context to ensure it's not nil and has a length greater than zero, preventing errors with empty contexts.
Activity
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.

@nitram509
Copy link
Member Author

/gemini review

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

This pull request refactors the library to return native Go types from evaluation functions instead of custom FEEL types, significantly improving usability. While the core logic involving the new unwrapFEELValue function and getContextMap helper, along with extensive test updates, looks good, two potential Denial of Service (DoS) vulnerabilities were identified. These stem from recursive calls and pointer dereferencing without depth limits or cycle detection, which could lead to stack overflows or infinite loops with circular data structures. Additionally, there is one minor suggestion to improve a test helper.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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

This pull request refactors the FEEL engine to return native Go types instead of internal FEEL-specific types, which is a great enhancement for the library's usability. The core change is the unwrapFEELValue function that recursively converts FEEL types to their Go equivalents. The tests have been updated accordingly. I've found a couple of areas for improvement. There's a high-severity issue with how year-month durations are handled, leading to a lossy conversion and incorrect results. Additionally, there's a medium-severity issue in the new getContextMap helper where it silently ignores map entries with non-string keys. Addressing these points will make the new functionality more robust and correct.

@nitram509 nitram509 merged commit 05347be into main Mar 8, 2026
2 checks passed
@nitram509 nitram509 deleted the go-types branch March 8, 2026 15:09
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.

2 participants