Skip to content

Commit cd45b0b

Browse files
committed
Test has_subtype on recursive data types
The test fails without the fixes from fe8e589.
1 parent 85ac315 commit cd45b0b

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

unit/util/has_subtype.cpp

+30-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ static std::function<bool(const typet &)> is_type(const typet &t1)
2323
return f;
2424
}
2525

26-
SCENARIO("has_subtype", "[core][solvers][refinement][string_refinement]")
26+
SCENARIO("has_subtype", "[core][utils][has_subtype]")
2727
{
28-
const symbol_tablet symbol_table;
28+
symbol_tablet symbol_table;
2929
const namespacet ns(symbol_table);
3030

3131
const typet char_type = java_char_type();
@@ -63,4 +63,32 @@ SCENARIO("has_subtype", "[core][solvers][refinement][string_refinement]")
6363
REQUIRE_FALSE(has_subtype(ptr_type, is_type(int_type), ns));
6464
}
6565
}
66+
67+
GIVEN("a recursive struct definition")
68+
{
69+
symbol_typet symbol_type("A-struct");
70+
struct_typet::componentt comp("ptr", pointer_type(symbol_type));
71+
struct_typet struct_type;
72+
struct_type.components().push_back(comp);
73+
74+
symbolt s;
75+
s.type = struct_type;
76+
s.name = "A-struct";
77+
s.is_type = true;
78+
symbol_table.add(s);
79+
80+
THEN("has_subtype terminates")
81+
{
82+
REQUIRE_FALSE(
83+
has_subtype(struct_type, [&](const typet &t) { return false; }, ns));
84+
}
85+
THEN("symbol type is a subtype")
86+
{
87+
REQUIRE(has_subtype(struct_type, is_type(pointer_type(symbol_type)), ns));
88+
}
89+
THEN("struct type is a subtype")
90+
{
91+
REQUIRE(has_subtype(struct_type, is_type(struct_type), ns));
92+
}
93+
}
6694
}

0 commit comments

Comments
 (0)