From 43c5f081d769b0d9744d1b0355ae92a5667b9e2d Mon Sep 17 00:00:00 2001 From: Bobby Lucero Date: Wed, 6 Aug 2025 21:46:52 -0400 Subject: [PATCH] Error reporting fix --- source/Interpreter.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/source/Interpreter.cpp b/source/Interpreter.cpp index 351132a..0eeb250 100644 --- a/source/Interpreter.cpp +++ b/source/Interpreter.cpp @@ -406,8 +406,13 @@ Value Interpreter::visitCallExpr(const std::shared_ptr& expression) { if (callee.isFunction()) { Function* function = callee.asFunction(); if (arguments.size() != function->params.size()) { - throw std::runtime_error("Expected " + std::to_string(function->params.size()) + - " arguments but got " + std::to_string(arguments.size()) + "."); + std::string errorMsg = "Expected " + std::to_string(function->params.size()) + + " arguments but got " + std::to_string(arguments.size()) + "."; + if (errorReporter) { + errorReporter->reportError(expression->paren.line, expression->paren.column, "Runtime Error", + errorMsg, ""); + } + throw std::runtime_error(errorMsg); } // Check if this is a tail call @@ -476,7 +481,13 @@ Value Interpreter::visitCallExpr(const std::shared_ptr& expression) { } } - throw std::runtime_error("Can only call functions and classes."); + // Provide better error message with type information + std::string errorMsg = "Can only call functions, got " + callee.getType(); + if (errorReporter) { + errorReporter->reportError(expression->paren.line, expression->paren.column, "Runtime Error", + errorMsg, ""); + } + throw std::runtime_error(errorMsg); } Value Interpreter::visitArrayLiteralExpr(const std::shared_ptr& expr) {