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

Method conditionalNode

checker/checker.go:1283–1313  ·  view source on GitHub ↗
(node *ast.ConditionalNode)

Source from the content-addressed store, hash-verified

1281}
1282
1283func (v *Checker) conditionalNode(node *ast.ConditionalNode) Nature {
1284 c := v.visit(node.Cond)
1285 c = c.Deref(&v.config.NtCache)
1286 if !c.IsBool() && !c.IsUnknown(&v.config.NtCache) {
1287 return v.error(node.Cond, "non-bool expression (type %v) used as condition", c.String())
1288 }
1289
1290 t1 := v.visit(node.Exp1)
1291 t2 := v.visit(node.Exp2)
1292
1293 if t1.Nil && !t2.Nil {
1294 return t2
1295 }
1296 if !t1.Nil && t2.Nil {
1297 return t1
1298 }
1299 if t1.Nil && t2.Nil {
1300 return v.config.NtCache.NatureOf(nil)
1301 }
1302 if t1.AssignableTo(t2) {
1303 if t1.IsArray() && t2.IsArray() {
1304 e1 := t1.Elem(&v.config.NtCache)
1305 e2 := t2.Elem(&v.config.NtCache)
1306 if !e1.AssignableTo(e2) || !e2.AssignableTo(e1) {
1307 return v.config.NtCache.FromType(arrayType)
1308 }
1309 }
1310 return t1
1311 }
1312 return Nature{}
1313}
1314
1315func (v *Checker) arrayNode(node *ast.ArrayNode) Nature {
1316 var prev Nature

Callers 1

visitMethod · 0.95

Implementers 3

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

Calls 11

visitMethod · 0.95
errorMethod · 0.95
DerefMethod · 0.80
IsBoolMethod · 0.80
IsUnknownMethod · 0.80
NatureOfMethod · 0.80
AssignableToMethod · 0.80
IsArrayMethod · 0.80
ElemMethod · 0.80
FromTypeMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected