From bd9eac9056d7a167925fa8ca1f30934bc403d21b Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Thu, 12 Sep 2019 17:16:11 +0200 Subject: [PATCH] Better diagnostics for CantIndex error message --- src/Binder/Binder.cpp | 4 ++-- src/Diagnostics/ErrorMessages-EN-US.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Binder/Binder.cpp b/src/Binder/Binder.cpp index 07a018b..01dfcf9 100644 --- a/src/Binder/Binder.cpp +++ b/src/Binder/Binder.cpp @@ -730,7 +730,7 @@ namespace Porygon::Binder { auto indexerType = indexer->GetType(); if (!indexerType->CanBeIndexedWith(index->GetType().get())) { this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::CantIndex, index->GetStartPosition(), - index->GetLength()); + index->GetLength(), {indexerType->ToString(), index->GetType()->ToString()}); return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength()); } if (indexerType->GetClass() == TypeClass::UserData) { @@ -764,7 +764,7 @@ namespace Porygon::Binder { const auto &indexerType = indexer->GetType(); if (!indexerType->CanBeIndexedWithIdentifier(identifier.GetHash())) { this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::CantIndex, expression->GetStartPosition(), - expression->GetLength()); + expression->GetLength(), {indexerType->ToString(), identifier.GetDebugString()}); return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength()); } if (indexerType->GetClass() == TypeClass::UserData) { diff --git a/src/Diagnostics/ErrorMessages-EN-US.cpp b/src/Diagnostics/ErrorMessages-EN-US.cpp index fc2b310..40b00ee 100644 --- a/src/Diagnostics/ErrorMessages-EN-US.cpp +++ b/src/Diagnostics/ErrorMessages-EN-US.cpp @@ -13,7 +13,7 @@ namespace Porygon::Diagnostics { {DiagnosticCode ::CantAssignVariable, "Something went wrong while assigning variable."}, {DiagnosticCode ::VariableNotFound, "Variable not found."}, {DiagnosticCode ::ExpressionIsNotAFunction, "Called expression is not a function."}, - {DiagnosticCode ::CantIndex, "Unable to index value."}, + {DiagnosticCode ::CantIndex, "Unable to index type {0} with {1}."}, {DiagnosticCode ::InvalidReturnType, "Invalid return type."}, {DiagnosticCode ::ConditionNotABool, "A condition should return a bool."}, {DiagnosticCode ::InvalidTableValueType, "This is an invalid table value type."},