MCPcopy
hub / github.com/expr-lang/expr / binaryNode

Method binaryNode

checker/checker.go:320–509  ·  view source on GitHub ↗
(node *ast.BinaryNode)

Source from the content-addressed store, hash-verified

318}
319
320func (v *Checker) binaryNode(node *ast.BinaryNode) Nature {
321 l := v.visit(node.Left)
322 r := v.visit(node.Right)
323
324 l = l.Deref(&v.config.NtCache)
325 r = r.Deref(&v.config.NtCache)
326
327 switch node.Operator {
328 case "==", "!=":
329 if l.ComparableTo(&v.config.NtCache, r) {
330 return v.config.NtCache.FromType(boolType)
331 }
332
333 case "or", "||", "and", "&&":
334 if l.IsBool() && r.IsBool() {
335 return v.config.NtCache.FromType(boolType)
336 }
337 if l.MaybeCompatible(&v.config.NtCache, r, BoolCheck) {
338 return v.config.NtCache.FromType(boolType)
339 }
340
341 case "<", ">", ">=", "<=":
342 if l.IsNumber() && r.IsNumber() {
343 return v.config.NtCache.FromType(boolType)
344 }
345 if l.IsString() && r.IsString() {
346 return v.config.NtCache.FromType(boolType)
347 }
348 if l.IsTime() && r.IsTime() {
349 return v.config.NtCache.FromType(boolType)
350 }
351 if l.IsDuration() && r.IsDuration() {
352 return v.config.NtCache.FromType(boolType)
353 }
354 if l.MaybeCompatible(&v.config.NtCache, r, NumberCheck, StringCheck, TimeCheck, DurationCheck) {
355 return v.config.NtCache.FromType(boolType)
356 }
357
358 case "-":
359 if l.IsNumber() && r.IsNumber() {
360 return l.PromoteNumericNature(&v.config.NtCache, r)
361 }
362 if l.IsTime() && r.IsTime() {
363 return v.config.NtCache.FromType(durationType)
364 }
365 if l.IsTime() && r.IsDuration() {
366 return v.config.NtCache.FromType(timeType)
367 }
368 if l.IsDuration() && r.IsDuration() {
369 return v.config.NtCache.FromType(durationType)
370 }
371 if l.MaybeCompatible(&v.config.NtCache, r, NumberCheck, TimeCheck, DurationCheck) {
372 return Nature{}
373 }
374
375 case "*":
376 if l.IsNumber() && r.IsNumber() {
377 return l.PromoteNumericNature(&v.config.NtCache, r)

Callers 1

visitMethod · 0.95

Implementers 3

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

Calls 15

visitMethod · 0.95
errorMethod · 0.95
ArrayFromTypeFunction · 0.85
DerefMethod · 0.80
ComparableToMethod · 0.80
FromTypeMethod · 0.80
IsBoolMethod · 0.80
MaybeCompatibleMethod · 0.80
IsNumberMethod · 0.80
IsStringMethod · 0.80
IsTimeMethod · 0.80
IsDurationMethod · 0.80

Tested by

no test coverage detected