MCPcopy Index your code
hub / github.com/expr-lang/expr / unaryNode

Method unaryNode

checker/checker.go:291–318  ·  view source on GitHub ↗
(node *ast.UnaryNode)

Source from the content-addressed store, hash-verified

289}
290
291func (v *Checker) unaryNode(node *ast.UnaryNode) Nature {
292 nt := v.visit(node.Node)
293 nt = nt.Deref(&v.config.NtCache)
294
295 switch node.Operator {
296
297 case "!", "not":
298 if nt.IsBool() {
299 return v.config.NtCache.FromType(boolType)
300 }
301 if nt.IsUnknown(&v.config.NtCache) {
302 return v.config.NtCache.FromType(boolType)
303 }
304
305 case "+", "-":
306 if nt.IsNumber() {
307 return nt
308 }
309 if nt.IsUnknown(&v.config.NtCache) {
310 return Nature{}
311 }
312
313 default:
314 return v.error(node, "unknown operator (%s)", node.Operator)
315 }
316
317 return v.error(node, `invalid operation: %s (mismatched type %s)`, node.Operator, nt.String())
318}
319
320func (v *Checker) binaryNode(node *ast.BinaryNode) Nature {
321 l := v.visit(node.Left)

Callers 1

visitMethod · 0.95

Implementers 3

Configconf/config.go
Checkerchecker/checker.go
OperatorOverloadingpatcher/operator_override.go

Calls 8

visitMethod · 0.95
errorMethod · 0.95
DerefMethod · 0.80
IsBoolMethod · 0.80
FromTypeMethod · 0.80
IsUnknownMethod · 0.80
IsNumberMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected