visitPatternVariableDeclarationStatement method
Visit a SPatternVariableDeclarationStatement.
Implementation
@override
Object? visitPatternVariableDeclarationStatement(
SPatternVariableDeclarationStatement node,
) {
final patternDecl = node.declaration;
final pattern = patternDecl.pattern;
final initializer = patternDecl.expression;
// Evaluate the right-hand side value
final rhsValue = initializer.accept<Object?>(this);
// Match and bind the pattern to the value
try {
_matchAndBind(pattern, rhsValue, environment);
} on PatternMatchD4rtException catch (e) {
// Convert pattern match failures to standard RuntimeError for now
throw RuntimeD4rtException("Pattern match failed: ${e.message}");
} catch (e, s) {
// Add stack trace capture
Logger.error(
"during pattern binding: $e\nStack trace:\n$s",
); // Display the stack trace
// Catch other potential errors during binding
throw RuntimeD4rtException("Error during pattern binding: $e");
}
return null;
}