Skip to content
Open
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
19 changes: 16 additions & 3 deletions assertion/function/assertiontree/root_assertion_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1191,9 +1191,22 @@ func (r *RootAssertionNode) isType(expr ast.Expr) bool {
// even when the slice itself is nil, i.e, one of [:0] [0:0] [0:] [:] [:0:0] [0:0:0]
func (r *RootAssertionNode) isZeroSlicing(expr *ast.SliceExpr) bool {
l, h, m := expr.Low, expr.High, expr.Max
return ((l == nil || r.isIntZero(l)) && r.isIntZero(h) && m == nil) || // [:0] [0:0]
((l == nil || r.isIntZero(l)) && h == nil && m == nil) || // [0:] [:]
((l == nil || r.isIntZero(l)) && r.isIntZero(h) && r.isIntZero(m)) // [:0:0] [0:0:0]
highIsFunc := false
lowIsFunc := false
switch h.(type) {
case *ast.CallExpr:
highIsFunc = true
}

switch l.(type) {
case *ast.CallExpr:
lowIsFunc = true
}

return ((l == nil || r.isIntZero(l) || lowIsFunc) && r.isIntZero(h) && m == nil) || // [:0] [0:0] [len(x):0]
((l == nil || r.isIntZero(l) || lowIsFunc) && h == nil && m == nil) || // [0:] [:] [len(x):]
((l == nil || r.isIntZero(l) || lowIsFunc) && r.isIntZero(h) && r.isIntZero(m)) || // [:0:0] [0:0:0] [len(x):0] [len(x):0:0]
((l == nil || r.isIntZero(l) || lowIsFunc) && highIsFunc) // [:len(x)] [0:len(x)] [len(x):len(x)]
}

// isIntZero returns if the given expression is evaluated to integer zero at compile time. For
Expand Down