Skip to content

Commit

Permalink
topdown/type: Fix inconsistent is_<type> return values.
Browse files Browse the repository at this point in the history
Fixes open-policy-agent#4943

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
  • Loading branch information
philipaconrad committed Aug 29, 2022
1 parent 26da19d commit 370c1a8
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 18 deletions.
3 changes: 2 additions & 1 deletion test/cases/testdata/typebuiltin/test-typebuiltin-0829.yaml
Expand Up @@ -9,4 +9,5 @@ cases:
}
note: typebuiltin/is_number
query: data.generated.p = x
want_result: []
want_result:
- x: false
3 changes: 2 additions & 1 deletion test/cases/testdata/typebuiltin/test-typebuiltin-0830.yaml
Expand Up @@ -9,4 +9,5 @@ cases:
}
note: typebuiltin/is_number
query: data.generated.p = x
want_result: []
want_result:
- x: false
3 changes: 2 additions & 1 deletion test/cases/testdata/typebuiltin/test-typebuiltin-0833.yaml
Expand Up @@ -9,4 +9,5 @@ cases:
}
note: typebuiltin/is_string
query: data.generated.p = x
want_result: []
want_result:
- x: false
3 changes: 2 additions & 1 deletion test/cases/testdata/typebuiltin/test-typebuiltin-0834.yaml
Expand Up @@ -9,4 +9,5 @@ cases:
}
note: typebuiltin/is_string
query: data.generated.p = x
want_result: []
want_result:
- x: false
3 changes: 2 additions & 1 deletion test/cases/testdata/typebuiltin/test-typebuiltin-0837.yaml
Expand Up @@ -9,4 +9,5 @@ cases:
}
note: typebuiltin/is_boolean
query: data.generated.p = x
want_result: []
want_result:
- x: false
3 changes: 2 additions & 1 deletion test/cases/testdata/typebuiltin/test-typebuiltin-0838.yaml
Expand Up @@ -9,4 +9,5 @@ cases:
}
note: typebuiltin/is_boolean
query: data.generated.p = x
want_result: []
want_result:
- x: false
3 changes: 2 additions & 1 deletion test/cases/testdata/typebuiltin/test-typebuiltin-0841.yaml
Expand Up @@ -9,4 +9,5 @@ cases:
}
note: typebuiltin/is_array
query: data.generated.p = x
want_result: []
want_result:
- x: false
3 changes: 2 additions & 1 deletion test/cases/testdata/typebuiltin/test-typebuiltin-0843.yaml
Expand Up @@ -9,4 +9,5 @@ cases:
}
note: typebuiltin/is_set
query: data.generated.p = x
want_result: []
want_result:
- x: false
3 changes: 2 additions & 1 deletion test/cases/testdata/typebuiltin/test-typebuiltin-0845.yaml
Expand Up @@ -9,4 +9,5 @@ cases:
}
note: typebuiltin/is_object
query: data.generated.p = x
want_result: []
want_result:
- x: false
3 changes: 2 additions & 1 deletion test/cases/testdata/typebuiltin/test-typebuiltin-0847.yaml
Expand Up @@ -9,4 +9,5 @@ cases:
}
note: typebuiltin/is_null
query: data.generated.p = x
want_result: []
want_result:
- x: false
16 changes: 8 additions & 8 deletions topdown/type.go
@@ -1,4 +1,4 @@
// Copyright 2018 The OPA Authors. All rights reserved.
// Copyright 2022 The OPA Authors. All rights reserved.
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.

Expand All @@ -13,7 +13,7 @@ func builtinIsNumber(a ast.Value) (ast.Value, error) {
case ast.Number:
return ast.Boolean(true), nil
default:
return nil, BuiltinEmpty{}
return ast.Boolean(false), nil
}
}

Expand All @@ -22,7 +22,7 @@ func builtinIsString(a ast.Value) (ast.Value, error) {
case ast.String:
return ast.Boolean(true), nil
default:
return nil, BuiltinEmpty{}
return ast.Boolean(false), nil
}
}

Expand All @@ -31,7 +31,7 @@ func builtinIsBoolean(a ast.Value) (ast.Value, error) {
case ast.Boolean:
return ast.Boolean(true), nil
default:
return nil, BuiltinEmpty{}
return ast.Boolean(false), nil
}
}

Expand All @@ -40,7 +40,7 @@ func builtinIsArray(a ast.Value) (ast.Value, error) {
case *ast.Array:
return ast.Boolean(true), nil
default:
return nil, BuiltinEmpty{}
return ast.Boolean(false), nil
}
}

Expand All @@ -49,7 +49,7 @@ func builtinIsSet(a ast.Value) (ast.Value, error) {
case ast.Set:
return ast.Boolean(true), nil
default:
return nil, BuiltinEmpty{}
return ast.Boolean(false), nil
}
}

Expand All @@ -58,7 +58,7 @@ func builtinIsObject(a ast.Value) (ast.Value, error) {
case ast.Object:
return ast.Boolean(true), nil
default:
return nil, BuiltinEmpty{}
return ast.Boolean(false), nil
}
}

Expand All @@ -67,7 +67,7 @@ func builtinIsNull(a ast.Value) (ast.Value, error) {
case ast.Null:
return ast.Boolean(true), nil
default:
return nil, BuiltinEmpty{}
return ast.Boolean(false), nil
}
}

Expand Down

0 comments on commit 370c1a8

Please sign in to comment.