Made use of the null return value

This commit is contained in:
arookas 2016-02-03 23:22:54 -05:00
parent 908ceedc58
commit 7a81a4db2c

View file

@ -98,10 +98,10 @@ namespace arookas {
sunVariableSymbol DeclareVariable(sunIdentifier node, sunSymbolModifiers modifiers) { sunVariableSymbol DeclareVariable(sunIdentifier node, sunSymbolModifiers modifiers) {
var local = (modifiers & sunSymbolModifiers.Local) != 0; var local = (modifiers & sunSymbolModifiers.Local) != 0;
var name = MangleSymbolName(node.Value, node.Location.ScriptId, false, local); var name = MangleSymbolName(node.Value, node.Location.ScriptId, false, local);
if (Scopes.Any(i => i.GetIsDeclared(name))) { var symbol = Scopes.DeclareVariable(name);
if (symbol == null) {
throw new sunRedeclaredVariableException(node); throw new sunRedeclaredVariableException(node);
} }
var symbol = Scopes.DeclareVariable(name);
if (Scopes.Top.Type == sunScopeType.Script) { // global-scope variables are added to the symbol table if (Scopes.Top.Type == sunScopeType.Script) { // global-scope variables are added to the symbol table
SymbolTable.Add(symbol); SymbolTable.Add(symbol);
} }
@ -113,10 +113,11 @@ namespace arookas {
sunConstantSymbol DeclareConstant(sunIdentifier node, sunExpression expression, sunSymbolModifiers modifiers) { sunConstantSymbol DeclareConstant(sunIdentifier node, sunExpression expression, sunSymbolModifiers modifiers) {
var local = (modifiers & sunSymbolModifiers.Local) != 0; var local = (modifiers & sunSymbolModifiers.Local) != 0;
var name = MangleSymbolName(node.Value, node.Location.ScriptId, false, local); var name = MangleSymbolName(node.Value, node.Location.ScriptId, false, local);
if (Scopes.Any(i => i.GetIsDeclared(name))) { var symbol = Scopes.DeclareConstant(name, expression);
if (symbol == null) {
throw new sunRedeclaredVariableException(node); throw new sunRedeclaredVariableException(node);
} }
return Scopes.DeclareConstant(name, expression); return symbol;
} }
public sunStorableSymbol ResolveStorable(sunIdentifier node) { public sunStorableSymbol ResolveStorable(sunIdentifier node) {