count() without a predicate compiles for non-bool arrays and fails at run time
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 25/100
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
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus expr-lang/expr
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
expr-lang/expr#1037 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 57/100
Maintainer antworten meist innerhalb von 1 Tag
-
OSS-Fuzz issue 578739164Offenwontfix
Schwierigkeit 4/5 1-2 Tage Anfängerfreundlichkeit 35/100
expr-lang/expr#995 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
`find`, `findIndex`, `first` and `get` are type-checked as the element type where they return nilEvtl. wieder frei Ein Pull Request dazu wurde ohne Merge geschlossen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 65/100
expr-lang/expr#989 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
expr-lang/expr#975 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
provider-key submission
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
opentofu/registry#6740 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
type:bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
nightgauge/nightgauge#3713 ·
Maintainer antworten meist innerhalb von 1 Tag
-
fix: restore GitHub issue templates and check their license headersEvtl. vergeben @slievrly hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 2 Tagen
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag