`ValueGetter` is not supported in`map`

未关闭
#886 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@draarivpatel-ui 已经在做这个了。

开始于 2026年11月25日。

  • #1030 来自 @draarivpatel-ui —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
42/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
go
领域
backend

调研方向

从 Go playground 的复现开始,跟踪针对 params map,value.ValueGetter 在 expr.Compile 和 vm.Run 之间是如何处理的。检查现有 evaluator 对 map 值的处理行为,并确认报告中的表达式不再产生无效操作错误。

由索引模型根据 Issue 内容生成。

描述

ValueGetter is not supported inmap:

https://go.dev/play/p/cutaKAgIxHj

package main

import (
	"fmt"

	"github.com/expr-lang/expr"
	"github.com/expr-lang/expr/patcher/value"
	"github.com/expr-lang/expr/vm"
)

type customInt struct {
	Int int
}

func (v *customInt) AsInt() int {
	return v.Int
}

func (v *customInt) AsAny() any {
	return v.Int
}

func main() {
	env := map[string]any{
		"params": map[string]any{
			"ValueOne": &customInt{1},
			"ValueTwo": &customInt{2},
		},
	}

	program, err := expr.Compile(
		"params.ValueOne + params.ValueTwo",
		expr.Env(env), 
		value.ValueGetter,
	)
	if err != nil {
		fmt.Println(err)
		return
	}

	out, err := vm.Run(program, env)
	if err != nil {
		panic(err)
	}

	fmt.Println(out)
}

The code above produced the following error:

panic: invalid operation: main.customInt + main.customInt (1:17)
	 | params.ValueOne + params.ValueTwo
	 | ................^

goroutine 1 [running]:
main.main()
	/tmp/sandbox3933238168/prog.go:43 +0x249

Program exited.

In my scenario, it's not possible to define a specific struct. Is there any way to solve this problem?

主要语言
Go
星标
8.1k
派生
544
平均合并
1 天 9 小时
30 天内合并 PR
25

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

expr-lang/expr 的其他 Issue

查看 expr-lang/expr 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。