Fix bug with empty arrays in match (#207)

This commit is contained in:
Mike Voronov 2021-12-29 20:01:49 +03:00 committed by GitHub
parent e6193ea4de
commit 401d8c06fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 1 deletions

View File

@ -47,6 +47,11 @@ pub(crate) fn are_matchable_eq<'ctx>(
compare_matchable(matchable, exec_ctx, make_string_comparator(value)) compare_matchable(matchable, exec_ctx, make_string_comparator(value))
} }
(EmptyArray, EmptyArray) => Ok(true),
(EmptyArray, matchable) | (matchable, EmptyArray) => {
compare_matchable(matchable, exec_ctx, make_object_comparator(JValue::Array(vec![])))
}
(Boolean(left_boolean), Boolean(right_boolean)) => Ok(left_boolean == right_boolean), (Boolean(left_boolean), Boolean(right_boolean)) => Ok(left_boolean == right_boolean),
(Boolean(value), matchable) | (matchable, Boolean(value)) => { (Boolean(value), matchable) | (matchable, Boolean(value)) => {
compare_matchable(matchable, exec_ctx, make_object_comparator((*value).into())) compare_matchable(matchable, exec_ctx, make_object_comparator((*value).into()))
@ -63,7 +68,6 @@ pub(crate) fn are_matchable_eq<'ctx>(
Ok(left_value == right_value) Ok(left_value == right_value)
} }
_ => Ok(false),
} }
} }

View File

@ -0,0 +1,50 @@
/*
* Copyright 2021 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use air_test_utils::prelude::*;
use fstrings::f;
use fstrings::format_args_f;
#[test]
// test for github.com/fluencelabs/aquavm/issues/206
fn issue_206() {
let peer_1_id = "peer_1_id";
let mut peer_1 = create_avm(echo_call_service(), peer_1_id);
let script = f!(r#"
(new $result
(seq
(xor
(match $result []
(xor
(ap "is nil" $result)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
(ap "not" $result)
)
(call %init_peer_id% ("op" "identity") [$result] result-fix)
)
)
"#);
let result = checked_call_vm!(peer_1, peer_1_id, &script, "", "");
let actual_trace = trace_from_result(&result);
let expected_trace = vec![executed_state::ap(Some(0)), executed_state::scalar(json!(["is nil"]))];
assert_eq!(actual_trace, expected_trace);
}

View File

@ -19,3 +19,4 @@ mod issue_173;
mod issue_177; mod issue_177;
mod issue_178; mod issue_178;
mod issue_180; mod issue_180;
mod issue_206;