From f638c25483bc45ede5788e65c2ee2e6a0c14b4bc Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 7 Dec 2018 18:23:50 +0100 Subject: [PATCH] Fixes for binding table contents when binder can't be aware of table contents, such as with CSharp calls --- Upsilon/Binder/Binder.cs | 11 ++++++++++- .../Binder/VariableSymbols/TableVariableSymbol.cs | 12 ++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Upsilon/Binder/Binder.cs b/Upsilon/Binder/Binder.cs index 98bfbef..c08a717 100644 --- a/Upsilon/Binder/Binder.cs +++ b/Upsilon/Binder/Binder.cs @@ -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); diff --git a/Upsilon/Binder/VariableSymbols/TableVariableSymbol.cs b/Upsilon/Binder/VariableSymbols/TableVariableSymbol.cs index 5560018..ae1f7f0 100644 --- a/Upsilon/Binder/VariableSymbols/TableVariableSymbol.cs +++ b/Upsilon/Binder/VariableSymbols/TableVariableSymbol.cs @@ -6,11 +6,19 @@ namespace Upsilon.Binder.VariableSymbols public class TableVariableSymbol : VariableSymbol { public Dictionary Variables { get; } - + public bool ContentAware { get; } public TableVariableSymbol(string name, bool local, Dictionary 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(); + ContentAware = false; } } } \ No newline at end of file