@@ -913,7 +913,6 @@ codet java_string_library_preprocesst::make_equals_function_code(
913
913
const source_locationt &loc,
914
914
symbol_table_baset &symbol_table)
915
915
{
916
- // TODO: Code should return false if Object is not String.
917
916
code_blockt code;
918
917
exprt::operandst ops;
919
918
for (const auto &p : type.parameters ())
@@ -923,8 +922,30 @@ codet java_string_library_preprocesst::make_equals_function_code(
923
922
}
924
923
exprt::operandst args=process_equals_function_operands (
925
924
ops, loc, symbol_table, code);
926
- code.add (code_return_function_application (
927
- ID_cprover_string_equal_func, args, type.return_type (), symbol_table));
925
+
926
+ member_exprt class_identifier (
927
+ checked_dereference (ops[1 ], ops[1 ].type ().subtype ()),
928
+ " @class_identifier" ,
929
+ string_typet ());
930
+
931
+ // Check the object argument is a String.
932
+ equal_exprt arg_is_string (
933
+ class_identifier, constant_exprt (" java::java.lang.String" , string_typet ()));
934
+
935
+ // Check content equality
936
+ const symbolt string_equals_sym = get_fresh_aux_symbol (
937
+ java_boolean_type (), " string_equals" , " str_eq" , loc, ID_java, symbol_table);
938
+ const symbol_exprt string_equals = string_equals_sym.symbol_expr ();
939
+ code.add (code_declt (string_equals));
940
+ code.add (code_assignt (
941
+ string_equals,
942
+ make_function_application (
943
+ ID_cprover_string_equal_func, args, type.return_type (), symbol_table)));
944
+
945
+ code.add (code_returnt (if_exprt (
946
+ arg_is_string,
947
+ string_equals,
948
+ from_integer (false , java_boolean_type ()))));
928
949
return code;
929
950
}
930
951
0 commit comments