Skip to content

Commit fabeae2

Browse files
author
thk123
committed
Resolve issue with return type being erased
1 parent bee71fd commit fabeae2

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ Author: Daniel Kroening, [email protected]
4141
#include <analyses/cfg_dominators.h>
4242
#include <analyses/uncaught_exceptions_analysis.h>
4343

44-
#include <limits>
4544
#include <algorithm>
4645
#include <functional>
47-
#include <unordered_set>
46+
#include <goto-programs/remove_returns.h>
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 '?'
@@ -2106,7 +2107,18 @@ void java_bytecode_convert_methodt::convert_invoke(
21062107
// whereas the type given by the invoke instruction doesn't and is therefore
21072108
// less accurate.
21082109
if(method_symbol != symbol_table.symbols.end())
2109-
arg0.type() = to_java_method_type(method_symbol->second.type);
2110+
{
2111+
const auto &restored_type =
2112+
original_return_type(symbol_table, invoked_method_id);
2113+
// Note the number of parameters might change here due to constructors using
2114+
// invokespecial will have zero arguments (the `this` is added below)
2115+
// but the symbol for the <init> will have the this parameter.
2116+
INVARIANT(
2117+
to_java_method_type(arg0.type()).return_type().id() ==
2118+
restored_type.return_type().id(),
2119+
"Function return type must not change in kind");
2120+
arg0.type() = restored_type;
2121+
}
21102122

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

0 commit comments

Comments
 (0)