Skip to content

Commit 3f0f776

Browse files
authored
Merge pull request #4137 from smowton/smowton/fix/java-static-field-generic-types
Java frontend: get qualified generic types of static fields
2 parents 2f1514e + 35213c4 commit 3f0f776

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
public class Test<T> {
3+
4+
public static Test<Integer> static_field;
5+
6+
public static Test<Integer> test() {
7+
8+
return static_field;
9+
10+
}
11+
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CORE
2+
Test.class
3+
--function Test.test --validate-goto-model --show-goto-functions
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
Test\.test:\(\)LTest;#return_value = static_field;
7+
--
8+
^warning: ignoring
9+
--
10+
This checks that the return value type matches the static field -- if it didn't,
11+
either --validate-goto-model would throw because of a mismatching assignment, or
12+
a cast would be used to adjust the type.
13+
14+
The original motivation for this test was that generic field references could
15+
accidentally omit generic arguments that were present in function types.

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,12 +1529,12 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
15291529
const bool is_assertions_disabled_field=
15301530
field_name.find("$assertionsDisabled")!=std::string::npos;
15311531

1532-
const symbol_exprt symbol_expr(
1533-
get_static_field(arg0.get_string(ID_class), field_name), arg0.type());
1532+
const irep_idt field_id(
1533+
get_static_field(arg0.get_string(ID_class), field_name));
15341534

1535-
INVARIANT(
1536-
symbol_table.has_symbol(symbol_expr.get_identifier()),
1537-
"getstatic symbol should have been created before method conversion");
1535+
// Symbol should have been populated by java_bytecode_convert_class:
1536+
const symbol_exprt symbol_expr(
1537+
symbol_table.lookup_ref(field_id).symbol_expr());
15381538

15391539
convert_getstatic(
15401540
arg0, symbol_expr, is_assertions_disabled_field, c, results);
@@ -1549,12 +1549,12 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
15491549
PRECONDITION(op.size() == 1 && results.empty());
15501550
const auto &field_name=arg0.get_string(ID_component_name);
15511551

1552-
const symbol_exprt symbol_expr(
1553-
get_static_field(arg0.get_string(ID_class), field_name), arg0.type());
1552+
const irep_idt field_id(
1553+
get_static_field(arg0.get_string(ID_class), field_name));
15541554

1555-
INVARIANT(
1556-
symbol_table.has_symbol(symbol_expr.get_identifier()),
1557-
"putstatic symbol should have been created before method conversion");
1555+
// Symbol should have been populated by java_bytecode_convert_class:
1556+
const symbol_exprt symbol_expr(
1557+
symbol_table.lookup_ref(field_id).symbol_expr());
15581558

15591559
c = convert_putstatic(i_it->source_location, arg0, op, symbol_expr);
15601560
}

0 commit comments

Comments
 (0)