-
Notifications
You must be signed in to change notification settings - Fork 5.4k
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eq
for Bytes
returns true
for unequal Bytes
#4868
Comments
Could you add assert(string_a.as_bytes() == string_b.as_bytes()); above the last line to see if that fails? |
This fails. Seems like there might be a problem with the |
If that also fails then it's the |
If |
We check the length first which seems to work everywhere else sway/sway-lib-std/src/bytes.sw Lines 605 to 616 in cab7e33
|
Maybe the length is set wrong? Like zero or something? |
let string_a = String::from_ascii_str("Hello World");
assert_eq(string_a.as_bytes().len(), 11);
let string_b = String::from_ascii_str("NoNoNo");
assert_eq(string_b.as_bytes().len(), 6); It would seem that the len is OK. Tried changing |
I think it's related to the where clause with the pub fn takes_generics_with_where_clause<T>(gen_1: T, gen_2: T) -> bool where T: Eq {
// This evaluates the opposite
return gen_1 != gen_2;
// This evaluates the opposite
return gen_1 == gen_2;
// This evaluates the opposite
if (gen_1 != gen_2) {
return false;
}
// This has an internal compiler error
if (gen_1 == gen_2) {
return true;
}
} The |
Sorry correction, any case where we are checking for equal will not evaluate to This is a minimal repo: use std::string::String;
use std::assert::assert_eq;
use std::assert::assert;
pub fn test_1<T>(gen_1: T, gen_2: T) -> bool where T: Eq {
// This evaluate the opposite
gen_1 != gen_2
}
pub fn test_2<T>(gen_1: T, gen_2: T) -> bool where T: Eq {
// This evaluates to Failing call to `std::assert::assert`
gen_1 == gen_2
}
pub fn test_3<T>(gen_1: T, gen_2: T) -> bool where T: Eq {
// This evaluate the opposite
if (gen_1 != gen_2) {
return false;
}
return true;
}
pub fn test_4<T>(gen_1: T, gen_2: T) -> bool where T: Eq {
// This has an internal compiler error
if (gen_1 == gen_2) {
return true;
}
return false;
}
#[test]
fn foo() {
let string_a = String::from_ascii_str("Hello World");
assert_eq(string_a.as_bytes().len(), 11);
let string_b = String::from_ascii_str("NoNoNo");
assert_eq(string_b.as_bytes().len(), 6);
// Should eval to true
assert(false == test_1(string_a.as_bytes(), string_b.as_bytes()));
// Should eval to false
// This evaluates to Failing call to `std::assert::assert`
// Will not pass either case but compiles
assert(false == test_2(string_a.as_bytes(), string_b.as_bytes()));
// Should eval to false
assert(true == test_3(string_a.as_bytes(), string_b.as_bytes()));
// Should eval to false
// Internal compiler error: Verification failed: Expression used for conditional is not a boolean.
assert(true == test_4(string_a.as_bytes(), string_b.as_bytes()));
} |
I triaged this a little bit and it appears to be the same problem that is seen in #4770. |
Minimal example here: https://github.com/segfault-magnet/sway_bytes_eq_bug
forc build && cargo test
Tested on
forc
0.42.1
andfuel-core
0.19
The text was updated successfully, but these errors were encountered: