Skip to content

Commit

Permalink
Print object information on Z3TypeError (WIP)
Browse files Browse the repository at this point in the history
ref #776
  • Loading branch information
jklmnn committed Oct 14, 2022
1 parent e91b737 commit 4512f0b
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions rflx/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,9 @@ def z3expr(self) -> z3.ArithRef:
left = self.left.z3expr()
right = self.right.z3expr()
if not isinstance(left, z3.ArithRef) or not isinstance(right, z3.ArithRef):
raise Z3TypeError("subtracting non-arithmetic terms")
raise Z3TypeError(
f"subtracting non-arithmetic terms: {repr(left)} - {repr(right)}, {str(left)} - {str(right)}, {type(left)} - {type(right)}; {repr(self.left)} - {repr(self.right)}; {repr(self.left.type_)} - {repr(self.right.type_)}; {type(self.left.z3expr())} - {type(self.right.z3expr())}"
)
return left - right


Expand Down Expand Up @@ -1210,6 +1212,8 @@ def ada_expr(self) -> ada.Expr:
@lru_cache(maxsize=None)
def z3expr(self) -> z3.ExprRef:
if self.type_ == rty.BOOLEAN:
if isinstance(self.type_, rty.Integer):
raise ValueError(f"{repr(self)}")
return z3.Bool(self.name)
if self.negative:
return -z3.Int(self.name)
Expand Down Expand Up @@ -1947,7 +1951,15 @@ def z3expr(self) -> z3.BoolRef:
left = self.left.z3expr()
right = self.right.z3expr()
if not isinstance(left, z3.ArithRef) or not isinstance(right, z3.ArithRef):
raise Z3TypeError("less relation between non-arithmetic terms")
l = None
r = None
if isinstance(self.left, Variable):
l = type(z3.Int(self.left.name))
if isinstance(self.right, Variable):
r = type(z3.Int(self.right.name))
raise Z3TypeError(
f"less relation between non-arithmetic terms: {repr(left)} - {repr(right)}, {str(left)} - {str(right)}, {type(left)} - {type(right)}; {repr(self.left)} - {repr(self.right)}; {repr(self.left.type_)} - {repr(self.right.type_)}; {type(self.left.z3expr())} - {type(self.right.z3expr())} | {l}, {r}"
)
return left < right


Expand Down Expand Up @@ -2031,7 +2043,9 @@ def z3expr(self) -> z3.BoolRef:
left = self.left.z3expr()
right = self.right.z3expr()
if not isinstance(left, z3.ArithRef) or not isinstance(right, z3.ArithRef):
raise Z3TypeError("greater-equal relation between non-arithmetic terms")
raise Z3TypeError(
f"less relation between non-arithmetic terms: {repr(left)} - {repr(right)}, {str(left)} - {str(right)}, {type(left)} - {type(right)}"
)
return left >= right


Expand Down Expand Up @@ -2060,7 +2074,9 @@ def z3expr(self) -> z3.BoolRef:
left = self.left.z3expr()
right = self.right.z3expr()
if not isinstance(left, z3.ArithRef) or not isinstance(right, z3.ArithRef):
raise Z3TypeError("greater relation between non-arithmetic terms")
raise Z3TypeError(
f"less relation between non-arithmetic terms: {repr(left)} - {repr(right)}, {str(left)} - {str(right)}, {type(left)} - {type(right)}; {repr(self.left)} - {repr(self.right)}; {repr(self.left.type_)} - {repr(self.right.type_)}; {type(self.left.z3expr())} - {type(self.right.z3expr())}"
)
return left > right


Expand Down

0 comments on commit 4512f0b

Please sign in to comment.