Skip to content

Bug: IndexError instead of SolveFailure when using tuple syntax in rangelist with unsolvable constraints #255

@BanuAdrian

Description

@BanuAdrian

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 failure

Expected Behavior

Both cases should throw SolveFailure since the constraints are unsolvable:

  • Class constraint: self.a > 128
  • Inline constraint: self.a must 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)) throws IndexError: list index out of range
  • Multi-argument syntax vsc.rangelist(0, 50) correctly throws SolveFailure

Impact

This bug makes debugging constraint issues more difficult since:

  • The error message is misleading (IndexError instead 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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions