Skip to content

Commit f0c520e

Browse files
author
thk123
committed
Resolve issue with return type being erased
1 parent a1e398d commit f0c520e

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,17 @@ Author: Daniel Kroening, [email protected]
3636

3737
#include <goto-programs/cfg.h>
3838
#include <goto-programs/class_hierarchy.h>
39+
#include <goto-programs/remove_returns.h>
3940
#include <goto-programs/resolve_inherited_component.h>
4041

4142
#include <analyses/cfg_dominators.h>
4243
#include <analyses/uncaught_exceptions_analysis.h>
4344

44-
#include <limits>
4545
#include <algorithm>
4646
#include <functional>
47-
#include <unordered_set>
47+
#include <limits>
4848
#include <regex>
49+
#include <unordered_set>
4950

5051
/// Given a string of the format '?blah?', will return true when compared
5152
/// against a string that matches appart from any characters that are '?'
@@ -2105,7 +2106,18 @@ void java_bytecode_convert_methodt::convert_invoke(
21052106
// whereas the type given by the invoke instruction doesn't and is therefore
21062107
// less accurate.
21072108
if(method_symbol != symbol_table.symbols.end())
2108-
arg0.type() = to_java_method_type(method_symbol->second.type);
2109+
{
2110+
const auto &restored_type =
2111+
original_return_type(symbol_table, invoked_method_id);
2112+
// Note the number of parameters might change here due to constructors using
2113+
// invokespecial will have zero arguments (the `this` is added below)
2114+
// but the symbol for the <init> will have the this parameter.
2115+
INVARIANT(
2116+
to_java_method_type(arg0.type()).return_type().id() ==
2117+
restored_type.return_type().id(),
2118+
"Function return type must not change in kind");
2119+
arg0.type() = restored_type;
2120+
}
21092121

21102122
// Note arg0 and arg0.type() are subject to many side-effects in this method,
21112123
// then finally used to populate the call instruction.

0 commit comments

Comments
 (0)