Better error message if type is not indexable with type

This commit is contained in:
Deukhoofd 2018-11-19 14:29:35 +01:00
parent 86447d0a36
commit 2787d947b5
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
2 changed files with 6 additions and 2 deletions

View File

@ -427,8 +427,7 @@ namespace Upsilon.Binder
case Type.String when index.Type == Type.Number: case Type.String when index.Type == Type.Number:
return new BoundIndexExpression(expression, index, Type.String); return new BoundIndexExpression(expression, index, Type.String);
default: default:
//TODO: wrong type diagnostic \ _diagnostics.LogInvalidIndexExpression(expression.Type, index.Type, e.Span);
throw new Exception(expression.Type.ToString());
return new BoundLiteralExpression(new LuaNull()); return new BoundLiteralExpression(new LuaNull());
} }
} }

View File

@ -64,6 +64,11 @@ namespace Upsilon
{ {
LogError($"Cannot convert type '{actualType}' to '{expectedType}'", span); 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 public class DiagnosticsMessage