Skip to content

Commit 6158db1

Browse files
Fix parsing issue for empty records
Fixes #5
1 parent 0d93a4d commit 6158db1

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

pyvcg/driver/cvc5_smtlib.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def parse_enum(self):
338338

339339
def parse_record(self, typ):
340340
assert isinstance(typ, smt.Record)
341-
if self.peek("BRA") or not typ.is_recursive:
341+
if self.peek("BRA"):
342342
self.match("BRA")
343343
self.match("IDENTIFIER")
344344
if typ.name + "__cons" != self.ct.value: # pragma: no cover
@@ -351,11 +351,13 @@ def parse_record(self, typ):
351351
self.match("KET")
352352
else:
353353
self.match("IDENTIFIER")
354-
if typ.name + "__null" != self.ct.value: # pragma: no cover
355-
self.error("unexpected constructor %s (expected %s)" %
356-
(self.ct.value,
357-
typ.name + "__null"))
358-
rv = None
354+
if self.ct.value == typ.name + "__null" and typ.is_recursive:
355+
rv = None
356+
elif self.ct.value == typ.name + "__cons":
357+
rv = {}
358+
else: # pragma: no cover
359+
self.error("unexpected constructor %s" %
360+
self.ct.value)
359361
return rv
360362

361363

tests/testSmt.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,31 @@ def test_Recursive_Record(self):
10381038
"""
10391039
)
10401040

1041+
def test_Void_Records(self):
1042+
s_sort = smt.Record("Foo")
1043+
self.script.add_statement(smt.Record_Declaration(s_sort))
1044+
1045+
sym_a = smt.Constant(s_sort, "a")
1046+
self.script.add_statement(
1047+
smt.Constant_Declaration(sym_a,
1048+
relevant=True))
1049+
1050+
self.assertResult(
1051+
"sat",
1052+
"""
1053+
(set-logic QF_DT)
1054+
(set-option :produce-models true)
1055+
1056+
(declare-datatype Foo (
1057+
(Foo__cons)))
1058+
(declare-const a Foo)
1059+
(check-sat)
1060+
(get-value (a))
1061+
(exit)
1062+
"""
1063+
)
1064+
self.assertValue("a", {})
1065+
10411066
def test_UF_No_Body(self):
10421067
s_par = smt.Bound_Variable(smt.BUILTIN_INTEGER, "x")
10431068
s_fun = smt.Function("potato", smt.BUILTIN_INTEGER, s_par)

0 commit comments

Comments
 (0)