Throw exception if trying to add to a fixed size IList
This commit is contained in:
parent
f1ae0af244
commit
668d60ce46
|
@ -84,22 +84,30 @@ 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)
|
||||
{
|
||||
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
|
||||
{
|
||||
List[index] = value.ToCSharpObject();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue