-
Notifications
You must be signed in to change notification settings - Fork 31
Open
Description
Description
When using vsc.rangelist() with tuple syntax to specify a range constraint that conflicts with other constraints, PyVSC throws an IndexError instead of the expected SolveFailure exception. The same constraint using multi-argument syntax correctly throws SolveFailure.
Minimal Reproducible Example
import vsc
@vsc.randobj
class C():
def __init__(self):
self.a = vsc.rand_uint8_t()
@vsc.constraint
def constr(self):
self.a > 128
# Case 1: Tuple syntax - throws IndexError (BUG)
c = C()
try:
with c.randomize_with() as it:
it.a in vsc.rangelist((0, 50))
except Exception as e:
print("Exception:", type(e), e)
# Output:
# Exception: <class 'IndexError'> list index out of range
# Case 2: Multi-argument syntax - correctly throws SolveFailure
c = C()
try:
with c.randomize_with() as it:
it.a in vsc.rangelist(0, 50)
except Exception as e:
print("Exception:", type(e), e)
# Output:
# Solve failure: set 'solve_fail_debug=1' for more details
# Exception: <class 'vsc.model.solve_failure.SolveFailure'> solve failureExpected Behavior
Both cases should throw SolveFailure since the constraints are unsolvable:
- Class constraint:
self.a > 128 - Inline constraint:
self.amust be in range [0, 50] (tuple case) or equal to 0 or 50 (multi-arg case)
These constraints cannot be satisfied simultaneously, so both should result in SolveFailure.
Actual Behavior
- Tuple syntax
vsc.rangelist((0, 50))throwsIndexError: list index out of range - Multi-argument syntax
vsc.rangelist(0, 50)correctly throwsSolveFailure
Impact
This bug makes debugging constraint issues more difficult since:
- The error message is misleading (
IndexErrorinstead of constraint-related error) - Users cannot rely on consistent exception types for the same type of constraint conflict
- It may mask the actual constraint solving problem
Copilot