Can't successfully pass "this" as part of an array parameter to user-defined op
tl;dr
The error("missing") below is unexpected. In a group discussion there was consensus that this looks like a bug.
$ echo '"foo"' | zq -z 'op MyOp(r): (over r => (yield this)) MyOp([1,2,this])' -
1
2
error("missing")
Details
Repro is with Zed commit 6e61673.
Working my way up to the example above, all of these work as I'd expect.
$ zq -version
Version: v1.16.0-15-g6e61673c
$ echo '[1,2,"foo"]' | zq -z 'over this => (yield this)' -
1
2
"foo"
$ echo null | zq -z 'op MyOp(r): (over r => (yield this)) MyOp([1,2,"foo"])' -
1
2
"foo"
$ echo '[1,2,"foo"]' | zq -z 'op MyOp(r): (over r => (yield this)) MyOp(this)' -
1
2
"foo"
$ echo '"foo"' | zq -z 'op MyOp(r): (over r => (yield this)) yield [1,2,this] | MyOp(this)' -
1
2
"foo"
That last one was particularly suspicious because it showed that if I "laundered" the primitive this value in a separate step, it could be made to work. But this kind of trickery is not necessary elsewhere in the language, which gave me pause.
Did a little digging into this. Arguments in a user op can be either a const or path. Feeding [1,this] is actually an invalid argument for a user op. In your example what should really be happening is the compiler should really reporting be the error non-path arguments cannot have variable dependency. Observe:
$ echo '"foo"' | gzq 'op MyOp(r): (yield this) MyOp(this+"bar")' -
non-path arguments cannot have variable dependency at line 1, column 31:
op MyOp(r): (yield this) MyOp(this+"bar")
~~~~~~~~~~
This is what we should be getting in the above example.
See: https://zed.brimdata.io/docs/language/statements#arguments