count() without a predicate compiles for non-bool arrays and fails at run time

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

Maintainer thường phản hồi trong vòng 1 ngày

@minilan677-netizen đang làm issue này rồi.

Từ ngày 26/11/2026.

  • #1032 của @minilan677-netizen — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
25/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

Start by tracing how the checker handles count() without a predicate and compare it with the predicate form, which already rejects non-boolean results. Check how known element types differ from unknown types such as []any; the issue names no source files or tests. Done means known non-bool element types fail at compile time while bool and unknown element types still compile.

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

Mô tả

count() without a predicate counts the true elements of an array (count([true, false, true]) == 2). The checker doesn't look at the element type in that form, though. So an array whose element type is known and isn't bool compiles fine, then fails at run time on the VM's bool assertion:

env := map[string]any{"ints": []int{1, 2, 3}}

program, err := expr.Compile(`count(ints)`, expr.Env(env)) // err == nil
_, err = expr.Run(program, env)
// interface conversion: interface {} is int, not bool (1:1)

The same thing happens with count(1..3), count(filter(ints, # > 1)), count(map(ints, #)), and arrays of strings, structs or *bool.

The predicate form already rejects this at compile time:

count(ArrayOfInt, {#})
predicate should return boolean (got int) (1:19)

Expected: count(ints) gives a similar compile-time error. Arrays of bool, and arrays whose element type is unknown ([]any, untyped env), should keep compiling as they do now.

Checked on master (c4b0946) with Go 1.27.3.

Ngôn ngữ chính
Go
Star
8.1k
Fork
544
Merge trung bình
1 ngày 9 giờ
Pull request đã merge (30 ngày)
25

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

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.