`ValueGetter` is not supported in`map`
维护者通常 1 天内回复
评估
调研方向
从 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,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
expr-lang/expr 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 90/100
维护者通常 1 天内回复
-
count() without a predicate compiles for non-bool arrays and fails at run time可能已有人在做 @minilan677-netizen 于 2 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 25/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 57/100
维护者通常 1 天内回复
-
wontfix
难度 4/5 1-2 天 新手友好度 35/100
维护者通常 1 天内回复
-
`find`, `findIndex`, `first` and `get` are type-checked as the element type where they return nil可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 3/5 1-2 天 新手友好度 65/100
维护者通常 1 天内回复
相似的 Issue
-
factory:subtask
难度 1/5 1 小时以内 新手友好度 95/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 95/100
OneBusAway/watchdog#470 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 92/100
维护者通常 1 天内回复
-
area: session
难度 2/5 1-3 小时 新手友好度 72/100
charmbracelet/crush#4484 ·
维护者通常 1 天内回复
-
accepted good first issue
难度 1/5 1-3 小时 新手友好度 95/100