From fbb04303259c06a58e970c4a6fccadb1d3bdb92b Mon Sep 17 00:00:00 2001 From: arookas Date: Tue, 8 Mar 2016 02:21:09 -0500 Subject: [PATCH] Fixed: check against local function variables. --- ssc/context.cs | 7 +++++++ ssc/exceptions.cs | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/ssc/context.cs b/ssc/context.cs index 0eef991..f67cd8f 100644 --- a/ssc/context.cs +++ b/ssc/context.cs @@ -97,6 +97,13 @@ namespace arookas { } sunVariableSymbol DeclareVariable(sunIdentifier node, sunSymbolModifiers modifiers) { var local = (modifiers & sunSymbolModifiers.Local) != 0; +#if SSC_SCOPES + if (local && Scopes.Top.Type == sunScopeType.Function) { +#else + if (local && Scopes.Count > 1) { +#endif + throw new sunLocalFunctionVariableException(node); + } var name = MangleSymbolName(node.Value, node.Location.ScriptId, false, local); var symbol = Scopes.DeclareVariable(name); if (symbol == null) { diff --git a/ssc/exceptions.cs b/ssc/exceptions.cs index 27298df..b71e31c 100644 --- a/ssc/exceptions.cs +++ b/ssc/exceptions.cs @@ -267,4 +267,12 @@ namespace arookas { public sunConstantDeclarationException(sunVariableDeclaration node) : base(node) { } } + class sunLocalFunctionVariableException : sunNodeException { + public override string Message { + get { return "Only script-scope variables can be declared local."; } + } + + public sunLocalFunctionVariableException(sunNode node) + : base(node) { } + } }