visitPatternAssignment method

  1. @override
Object? visitPatternAssignment(
  1. SPatternAssignment node
)
override

Implementation

@override
Object? visitPatternAssignment(SPatternAssignment node) {
  // 1. Evaluate the right-hand side expression
  final rhsValue = node.expression.accept<Object?>(this);

  // 2. Match the pattern against the value and bind variables
  try {
    _matchAndBind(node.pattern, rhsValue, environment);
  } on PatternMatchD4rtException catch (e) {
    // Convert pattern match failures into standard RuntimeErrors for assignment expressions
    throw RuntimeD4rtException("Pattern assignment failed: ${e.message}");
  } catch (e) {
    // Catch other potential errors during binding
    throw RuntimeD4rtException("Error during pattern assignment: $e");
  }

  // 3. Pattern assignment expression evaluates to the RHS value
  return rhsValue;
}