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

Aperta
#1,031 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@minilan677-netizen ci sta già lavorando.

Dal 26/11/2026.

  • #1032 di @minilan677-netizen — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
go
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Go
Stelle
8.1k
Fork
544
Merge medio
1g 9h
PR unite (30g)
25

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di expr-lang/expr

Tutte le issue di expr-lang/expr

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.