diff --git a/Upsilon/Binder/Binder.cs b/Upsilon/Binder/Binder.cs index b0856da..2d83daf 100644 --- a/Upsilon/Binder/Binder.cs +++ b/Upsilon/Binder/Binder.cs @@ -25,6 +25,19 @@ namespace Upsilon.Binder public BoundScript BindScript(BlockStatementSyntax e) { var bound = BindStatement(e); + foreach (var unboundFunctionStatement in _unboundFunctions) + { + _scope = new BoundScope(_scope); + foreach (var valueParameter in unboundFunctionStatement.Value.Parameters) + { + _scope.SetVariable(valueParameter); + } + unboundFunctionStatement.Value.Block = + (BoundBlockStatement) BindBlockStatement(unboundFunctionStatement.Value.UnboundBlock); + _scope = _scope.ParentScope; + unboundFunctionStatement.Key.IsBound = true; + } + _unboundFunctions = new Dictionary(); return new BoundScript(bound); }