Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Panic when using pointer-type map as environment

Đang mở
#825 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
go
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu trong conf/env.go quanh dòng 25 và các dòng 38-43, sau đó đọc internal/deref/deref.go ở dòng 39 để so sánh giá trị đã dereference với giá trị được dùng cho các thao tác trên map. Tái hiện ví dụ con trỏ tới map và xác nhận rằng expr.Compile không còn panic, trong khi các môi trường map trực tiếp vẫn tiếp tục hoạt động.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

wontfix
📝Bug Description

The conf.Env() function panics when passed a pointer to a map (e.g., *map[string]any ) instead of a direct map value.
However, from the code perspective, the pointer type is intended to be supported.

// file: conf/env.go
// line: 25
...
v := reflect.ValueOf(env)
d := deref.Value(v)
...

// file: internal/deref/deref.go
// line: 39
func Value(v reflect.Value) reflect.Value {
	for v.Kind() == reflect.Ptr || v.Kind() == reflect.Interface {
		if v.IsNil() {
			return v
		}
		v = v.Elem()
	}
	return v
}
🌍 Environment
  • expr version : Latest (master branch)
  • Go version : 1.24
  • OS : All platforms
🔄 Steps to Reproduce
package main

import (
    "github.com/expr-lang/expr"
)

func main() {
    m := map[string]any{"foo": 42}

    env := &m

    _, err := expr.Compile("foo > 0", expr.Env(env))
    
    if err != nil {
        panic(err)
    }
}
✅ Expected Behavior

The function should handle pointer-to-map types gracefully by properly dereferencing the pointer before performing map operations. 🎯

❌ Actual Behavior
panic: reflect: call of reflect.Value.Len on ptr to non-array Value

goroutine 1 [running]:
reflect.Value.lenNonSlice({0x1011f8ca0?, 0x140000a4378?, 0x1400009c998?})
        /usr/local/go/src/reflect/value.go:1780 +0x220
reflect.Value.Len(...)
        /usr/local/go/src/reflect/value.go:1761
github.com/expr-lang/expr/conf.Env({0x1011f8ca0, 0x140000a4378})
        /Users/bytedance/go/pkg/mod/github.com/expr-lang/expr@v1.17.6/conf/env.go:38 +0x208
github.com/expr-lang/expr/conf.(*Config).WithEnv(0x140000de000, {0x1011f8ca0?, 0x140000a4378?})
        /Users/bytedance/go/pkg/mod/github.com/expr-lang/expr@v1.17.6/conf/config.go:64 +0x58
main.main.Env.func1(0x101219660?)
        /Users/bytedance/go/pkg/mod/github.com/expr-lang/expr@v1.17.6/expr.go:31 +0x24
github.com/expr-lang/expr.Compile({0x101187670, 0x7}, {0x1400009cf08, 0x1, 0x1400005c738?})
        /Users/bytedance/go/pkg/mod/github.com/expr-lang/expr@v1.17.6/expr.go:211 +0x17c
main.main()
        /Users/bytedance/projects/go/rule/main.go:12 +0xc8
exit status 2

🔍 Root Cause Analysis

In conf/env.go , lines 38-43, the code uses:

  • v.Len() ❌ fails on pointer types
  • v.MapKeys() ❌ fails on pointer types
  • v.MapIndex(key) ❌ fails on pointer types

The fix is to use the dereferenced value d (from deref.Value(v) ) for these operations. 💡

I have a working implementation ready that addresses this issue. Would you like me to submit a PR for this fix?

Ngôn ngữ chính
Go
Star
8k
Fork
529
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của expr-lang/expr

Tất cả issue của expr-lang/expr

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.