From 2787d947b551c5518de4544eb96ea2d9a2166af1 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Mon, 19 Nov 2018 14:29:35 +0100 Subject: [PATCH] Better error message if type is not indexable with type --- Upsilon/Binder/Binder.cs | 3 +-- Upsilon/Diagnostics.cs | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Upsilon/Binder/Binder.cs b/Upsilon/Binder/Binder.cs index b67b34f..8f7a080 100644 --- a/Upsilon/Binder/Binder.cs +++ b/Upsilon/Binder/Binder.cs @@ -427,8 +427,7 @@ namespace Upsilon.Binder case Type.String when index.Type == Type.Number: return new BoundIndexExpression(expression, index, Type.String); default: - //TODO: wrong type diagnostic - throw new Exception(expression.Type.ToString()); +\ _diagnostics.LogInvalidIndexExpression(expression.Type, index.Type, e.Span); return new BoundLiteralExpression(new LuaNull()); } } diff --git a/Upsilon/Diagnostics.cs b/Upsilon/Diagnostics.cs index 12f2cdb..bb27445 100644 --- a/Upsilon/Diagnostics.cs +++ b/Upsilon/Diagnostics.cs @@ -64,6 +64,11 @@ namespace Upsilon { LogError($"Cannot convert type '{actualType}' to '{expectedType}'", span); } + + public void LogInvalidIndexExpression(Type expressionType, Type indexType, TextSpan span) + { + LogError($"Cannot index type '{expressionType}' with type '{indexType}'", span); + } } public class DiagnosticsMessage