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:
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());
}
}

View File

@ -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