Don't allow indexing unregistered types on evaluation

This commit is contained in:
Deukhoofd 2019-02-19 12:48:57 +01:00
parent 02fb3867e1
commit 18ca112624
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
1 changed files with 17 additions and 0 deletions

View File

@ -47,6 +47,17 @@ namespace Upsilon.Binder
{ {
innerScope = scopeOwner.EvaluationScope; innerScope = scopeOwner.EvaluationScope;
} }
if (variable.Type == Type.Unknown)
{
throw new EvaluationException(state.Script.FileName,
$"Variable of type '{variable.Type}' is not a registered type, and can't be indexed.", Span);
}
if (variable.Type == Type.UserData && variable.Type is UndefinedUserDataTypeContainer userDataTypeContainer)
{
throw new EvaluationException(state.Script.FileName,
$"Variable of type '{userDataTypeContainer.UserData}' is not a registered type, and can't be indexed.", Span);
}
var indexer = Index.Evaluate(scope, diagnostics, ref state); var indexer = Index.Evaluate(scope, diagnostics, ref state);
return indexable.Get(diagnostics, Span, indexer, innerScope); return indexable.Get(diagnostics, Span, indexer, innerScope);
@ -87,6 +98,12 @@ namespace Upsilon.Binder
$"Variable of type '{variable.Type}' is not indexable.", Span); $"Variable of type '{variable.Type}' is not indexable.", Span);
} }
if (variable.Type == Type.UserData && variable.Type is UndefinedUserDataTypeContainer userDataTypeContainer)
{
throw new EvaluationException(state.Script.FileName,
$"Variable of type '{userDataTypeContainer.UserData}' is not a registered type, and can't be indexed.", Span);
}
var innerScope = scope; var innerScope = scope;
if (variable is IScopeOwner scopeOwner) if (variable is IScopeOwner scopeOwner)
{ {