Throw exception if trying to add to a fixed size IList

This commit is contained in:
Deukhoofd 2019-02-21 14:21:15 +01:00
parent f1ae0af244
commit 668d60ce46
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
1 changed files with 14 additions and 6 deletions

View File

@ -84,20 +84,28 @@ namespace Upsilon.BaseTypes.UserData
}
else
{
throw new ScriptRuntimeException(null,
$"Tried indexing a CSharp list with a value that's not an integer. Value: {scriptIndex.ToCSharpObject()}",
span, diagnostics.ScriptString.GetSpan(span));
throw new EvaluationException(null,
$"Tried indexing a CSharp list with a value that's not an integer. Value: {scriptIndex.ToCSharpObject()}.",
span);
}
index--;
if (index > List.Count)
{
throw new Exception(
$"Tried adding an item to a list at position {index}, but list is only of length {List.Count}");
throw new EvaluationException(null,
$"Tried adding an item to a list at position {index}, but list is only of length {List.Count}.", span);
}
if (index == List.Count)
{
List.Add(value.ToCSharpObject());
if (!List.IsFixedSize)
{
List.Add(value.ToCSharpObject());
}
else
{
throw new EvaluationException(null,
$"Tried adding an item to a list at position {index}, but list is of fixed size.", span);
}
}
else
{