Fixes for binding table contents when binder can't be aware of table contents, such as with CSharp calls

This commit is contained in:
Deukhoofd 2018-12-07 18:23:50 +01:00
parent bbab802f2d
commit f638c25483
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
2 changed files with 20 additions and 3 deletions

View File

@ -370,6 +370,10 @@ namespace Upsilon.Binder
((TableVariableSymbol) ((BoundVariableExpression) assignment).Variable.VariableSymbol)
.Variables);
}
else
{
variable = new TableVariableSymbol(name, isLocal);
}
}
else
{
@ -691,7 +695,12 @@ namespace Upsilon.Binder
var table = (BoundVariableExpression)expression;
var realTable = table.Variable;
var realIndex = (BoundLiteralExpression) index;
var variableDic = ((TableVariableSymbol) realTable.VariableSymbol).Variables;
var tableSymbol = ((TableVariableSymbol) realTable.VariableSymbol);
if (!tableSymbol.ContentAware)
{
return new BoundIndexExpression(expression, index, Type.Unknown, e.Span);
}
var variableDic = tableSymbol.Variables;
if (variableDic.TryGetValue(realIndex.Value.ToString(), out var variable))
{
return new BoundIndexExpression(expression, index, variable.Type, e.Span);

View File

@ -6,11 +6,19 @@ namespace Upsilon.Binder.VariableSymbols
public class TableVariableSymbol : VariableSymbol
{
public Dictionary<string, VariableSymbol> Variables { get; }
public bool ContentAware { get; }
public TableVariableSymbol(string name, bool local, Dictionary<string, VariableSymbol> variables)
:base (name, Type.Table, local)
{
Variables = variables;
Variables = variables;
ContentAware = true;
}
public TableVariableSymbol(string name, bool local)
:base (name, Type.Table, local)
{
Variables = new Dictionary<string, VariableSymbol>();
ContentAware = false;
}
}
}