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

Offen
#1,031 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@minilan677-netizen arbeitet bereits daran.

Seit 26.11.2026.

  • #1032 von @minilan677-netizen — offen

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
25/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Veraltet
Tech-Stack
go
Bereich
backend

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
Go
Sterne
8.1k
Forks
544
Ø Merge
1 T. 9 Std.
Gemergte PRs (30 T.)
25

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus expr-lang/expr

Alle Issues in expr-lang/expr

Ähnliche Issues

Weitere Issues zu Go

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.