Skip to content

Commit 34c185e

Browse files
author
thk123
committed
Unit test reproducing the bug described in TG-1058
When parsing fields that are of the inner class type, but the outer class is generic, we wrongly parse this a pointer to the outer type. This test demonstrates this problem.
1 parent 5b92002 commit 34c185e

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed
Binary file not shown.
Binary file not shown.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public class GenericClass<T>
2+
{
3+
class InnerClass
4+
{
5+
}
6+
7+
// class GenericInnerClass<V>
8+
// {
9+
// V field;
10+
// }
11+
12+
// class SameGenericParamInnerClass<T>
13+
// {
14+
// T field;
15+
// }
16+
17+
InnerClass field;
18+
// GenericInnerClass<Foo> field2;
19+
// SameGenericParamInnerClass<Foo> field3;
20+
21+
// GenericInnerClass<T> field4;
22+
// SameGenericParamInnerClass<T> field5;
23+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests for parsing generic classes
4+
5+
Author: DiffBlue Limited. All rights reserved.
6+
7+
\*******************************************************************/
8+
9+
#include <testing-utils/catch.hpp>
10+
#include <testing-utils/require_symbol.h>
11+
#include <testing-utils/require_type.h>
12+
13+
#include <util/cmdline.h>
14+
#include <util/config.h>
15+
#include <util/language.h>
16+
#include <util/prefix.h>
17+
#include <util/std_types.h>
18+
19+
#include <java_bytecode/java_bytecode_language.h>
20+
21+
#include <iostream>
22+
#include <testing-utils/load_java_class.h>
23+
24+
SCENARIO(
25+
"java_bytecode_parse_generic_inner_class",
26+
"[core][java_bytecode][java_bytecode_parse_generics]")
27+
{
28+
const symbol_tablet &new_symbol_table = load_java_class(
29+
"GenericClass", "./java_bytecode/java_bytecode_parse_generics");
30+
31+
std::string class_prefix = "java::GenericClass";
32+
THEN("There should be a symbol for GenericClass")
33+
{
34+
REQUIRE(new_symbol_table.has_symbol(class_prefix));
35+
const symbolt &class_symbol = new_symbol_table.lookup_ref(class_prefix);
36+
37+
const class_typet &class_type =
38+
require_symbol::require_complete_class(class_symbol);
39+
40+
THEN("The field component should be a pointer to GenericClass$InnerClass")
41+
{
42+
const struct_typet::componentt &field_component =
43+
require_type::require_component(class_type, "field");
44+
45+
require_type::require_pointer(
46+
field_component.type(), symbol_typet("java::GenericClass$InnerClass"));
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)