Fixed: check against local function variables.

This commit is contained in:
arookas 2016-03-08 02:21:09 -05:00
parent 2f6058d49f
commit fbb0430325
2 changed files with 15 additions and 0 deletions

View file

@ -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) {

View file

@ -267,4 +267,12 @@ namespace arookas {
public sunConstantDeclarationException(sunVariableDeclaration node)
: base(node) { }
}
class sunLocalFunctionVariableException : sunNodeException<sunNode> {
public override string Message {
get { return "Only script-scope variables can be declared local."; }
}
public sunLocalFunctionVariableException(sunNode node)
: base(node) { }
}
}