protected override void VisitReturnSyntax(ReturnSyntax pNode) { Store.SetValue("ReturnFound", pNode.Values.Count > 0); var count = Store.GetValue <int>("ReturnValueCount"); //If we have 0 return values it will be caught when we return to the method for checking return statements if (count > 0 && pNode.Values.Count != count) { CompilerErrors.MethodReturnCount(count, pNode.Span); } //Return statements can't be deferred otherwise we would defer forever! if (pNode.Deferred) { CompilerErrors.InvalidDefer(pNode.Span); } base.VisitReturnSyntax(pNode); }
protected override void VisitBlockSyntax(BlockSyntax pNode) { //Validate that deferred statements do not contain "return" statements //Report any unused variables if (pNode.Deferred && SyntaxHelper.LastStatementIsReturn(pNode)) { CompilerErrors.InvalidDefer(pNode.Span); } //Report any unused variables _locals.AddScope(); base.VisitBlockSyntax(pNode); foreach (var ld in _locals.GetVariablesInScope()) { if (!ld.IsReferenced) { CompilerErrors.VariableNeverUsed(ld.Name, ld.Span); } } _locals.RemoveScope(); }