Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions compiler/semantic/dagen.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,13 @@ func (d *dagen) expr(e sem.Expr) dag.Expr {
case *sem.AggFunc:
d.error(e, errors.New("call to aggregate function in non-aggregate context"))
return &dag.BadExpr{Kind: "BadExpr"}
case *sem.BadExpr:
// The translator reports an error for each bad expression so
// a DAG with bad expressions is never run. But bad expressions
// can appear in the functions assembled to evaluate a constant
// expression at compile time (see evaluator.maybeEval). Since
// functions are compiled only when called, these are harmless.
return &dag.BadExpr{Kind: "BadExpr"}
case *sem.ArrayExpr:
return &dag.ArrayExpr{
Kind: "ArrayExpr",
Expand Down
14 changes: 14 additions & 0 deletions compiler/semantic/ztests/const-eval-bad-func.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# An error in a function body is reported (not a panic) when a later
# expression is evaluated at compile time to check for a constant (here,
# the index this[k]).
spq: |
fn bad(x): nosuch(x)
values bad(this), this[k]

input: |
{a:1,k:"a"}

error: |
no such function at line 1, column 12:
fn bad(x): nosuch(x)
~~~~~~~~~
Loading