diff --git a/src/executor/op_code.rs b/src/executor/op_code.rs index 7982e95..8868c02 100644 --- a/src/executor/op_code.rs +++ b/src/executor/op_code.rs @@ -19,6 +19,12 @@ use crate::{ heap::Heap, }; +/// Explicitly compare only the data part of fat/trait/dyn Trait pointers. +#[allow(clippy::ptr_eq)] +fn trait_pointer_eq(p: *const T, q: *const U) -> bool { + (p as *const ()) == (q as *const ()) +} + #[derive(Clone, Debug)] pub enum ArrayReferenceKinds { Boolean, @@ -1268,7 +1274,7 @@ got: {:?}", }, (None, None) => Update::None, (Some(op1), Some(op2)) => { - if !Rc::::ptr_eq(&op1, &op2) { + if !trait_pointer_eq(op1.as_ref(), op2.as_ref()) { Update::GoTo(*size, *direction) } else { Update::None @@ -1286,7 +1292,7 @@ got: {:?}", (Some(_), None) | (None, Some(_)) => Update::None, (None, None) => Update::GoTo(*size, *direction), (Some(op1), Some(op2)) => { - if Rc::::ptr_eq(&op1, &op2) { + if trait_pointer_eq(op1.as_ref(), op2.as_ref()) { Update::GoTo(*size, *direction) } else { Update::None diff --git a/tests/control_flow.rs b/tests/control_flow.rs index 5c465e0..21a77a6 100644 --- a/tests/control_flow.rs +++ b/tests/control_flow.rs @@ -12,7 +12,9 @@ fn control_flow() -> Result<(), Box> { .stdout(predicate::str::contains("a / 2 == 5\n")) .stdout(predicate::str::contains("l / 2 != 5\n")) .stdout(predicate::str::contains("d:\n15\n")) - .stdout(predicate::str::contains("f > 10")); + .stdout(predicate::str::contains("f > 10")) + .stdout(predicate::str::contains("s1 == s2")) + .stdout(predicate::str::contains("s1 != s3")); Ok(()) } diff --git a/tests/data/control_flow/Main.class b/tests/data/control_flow/Main.class index aec2d07..d5be999 100644 Binary files a/tests/data/control_flow/Main.class and b/tests/data/control_flow/Main.class differ diff --git a/tests/data/control_flow/Main.java b/tests/data/control_flow/Main.java index 967fab4..d3cef95 100644 --- a/tests/data/control_flow/Main.java +++ b/tests/data/control_flow/Main.java @@ -37,5 +37,19 @@ public static void main(String[] args) { } else { System.out.println("f == 10"); } + + String s1 = "Hello World"; + String s2 = s1; + String s3 = "Goodbye"; + if (s1 == s2) { + System.out.println("s1 == s2"); + } else { + System.out.println("s1 != s2"); + } + if (s1 != s3) { + System.out.println("s1 != s3"); + } else { + System.out.println("s1 == s3"); + } } }