Throw exception if trying to add to a fixed size IList
This commit is contained in:
parent
f1ae0af244
commit
668d60ce46
|
@ -84,20 +84,28 @@ namespace Upsilon.BaseTypes.UserData
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new ScriptRuntimeException(null,
|
throw new EvaluationException(null,
|
||||||
$"Tried indexing a CSharp list with a value that's not an integer. Value: {scriptIndex.ToCSharpObject()}",
|
$"Tried indexing a CSharp list with a value that's not an integer. Value: {scriptIndex.ToCSharpObject()}.",
|
||||||
span, diagnostics.ScriptString.GetSpan(span));
|
span);
|
||||||
}
|
}
|
||||||
|
|
||||||
index--;
|
index--;
|
||||||
if (index > List.Count)
|
if (index > List.Count)
|
||||||
{
|
{
|
||||||
throw new Exception(
|
throw new EvaluationException(null,
|
||||||
$"Tried adding an item to a list at position {index}, but list is only of length {List.Count}");
|
$"Tried adding an item to a list at position {index}, but list is only of length {List.Count}.", span);
|
||||||
}
|
}
|
||||||
if (index == List.Count)
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue