Skip to content

Commit

Permalink
topdown/type+wasm: Fix inconsistent is_<type> return values. (#5064)
Browse files Browse the repository at this point in the history
Fixes #4943

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
  • Loading branch information
philipaconrad committed Aug 30, 2022
1 parent 26da19d commit a8de6a2
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 26 deletions.
2 changes: 1 addition & 1 deletion internal/compiler/wasm/opa/opa.go

Large diffs are not rendered by default.

Binary file modified internal/compiler/wasm/opa/opa.wasm
Binary file not shown.
3 changes: 2 additions & 1 deletion test/cases/testdata/typebuiltin/test-typebuiltin-0829.yaml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
14 changes: 7 additions & 7 deletions wasm/src/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,43 @@
OPA_BUILTIN
opa_value *opa_types_is_number(opa_value *v)
{
return opa_value_type(v) == OPA_NUMBER ? opa_boolean(true) : NULL;
return opa_boolean(opa_value_type(v) == OPA_NUMBER);
}

OPA_BUILTIN
opa_value *opa_types_is_string(opa_value *v)
{
return opa_value_type(v) == OPA_STRING ? opa_boolean(true) : NULL;
return opa_boolean(opa_value_type(v) == OPA_STRING);
}

OPA_BUILTIN
opa_value *opa_types_is_boolean(opa_value *v)
{
return opa_value_type(v) == OPA_BOOLEAN ? opa_boolean(true) : NULL;
return opa_boolean(opa_value_type(v) == OPA_BOOLEAN);
}

OPA_BUILTIN
opa_value *opa_types_is_array(opa_value *v)
{
return opa_value_type(v) == OPA_ARRAY ? opa_boolean(true) : NULL;
return opa_boolean(opa_value_type(v) == OPA_ARRAY);
}

OPA_BUILTIN
opa_value *opa_types_is_set(opa_value *v)
{
return opa_value_type(v) == OPA_SET ? opa_boolean(true) : NULL;
return opa_boolean(opa_value_type(v) == OPA_SET);
}

OPA_BUILTIN
opa_value *opa_types_is_object(opa_value *v)
{
return opa_value_type(v) == OPA_OBJECT ? opa_boolean(true) : NULL;
return opa_boolean(opa_value_type(v) == OPA_OBJECT);
}

OPA_BUILTIN
opa_value *opa_types_is_null(opa_value *v)
{
return opa_value_type(v) == OPA_NULL ? opa_boolean(true) : NULL;
return opa_boolean(opa_value_type(v) == OPA_NULL);
}

OPA_BUILTIN
Expand Down

0 comments on commit a8de6a2

Please sign in to comment.