Пример #1
0
        // Sets up the method's block.
        public override void SetupBlock()
        {
            if (context.block() != null)
            {
                block = new BlockAction(parseInfo.SetCallInfo(CallInfo), BlockScope, context.block());

                BlockTreeScan validation = new BlockTreeScan(doesReturnValue, parseInfo, this);
                validation.ValidateReturns();
                multiplePaths = validation.MultiplePaths;
            }
            foreach (var listener in listeners)
            {
                listener.Applied();
            }
        }
        // Sets up the method's block.
        public override void SetupBlock()
        {
            if (Context.block() != null)
            {
                Block = new BlockAction(parseInfo.SetCallInfo(CallInfo), methodScope.Child(), Context.block());

                // Validate returns.
                BlockTreeScan validation = new BlockTreeScan(DoesReturnValue, parseInfo, this);
                validation.ValidateReturns();
                MultiplePaths = validation.MultiplePaths;

                // If there is only one return statement, set SingleReturnValue.
                if (validation.Returns.Length == 1)
                {
                    SingleReturnValue = validation.Returns[0].ReturningValue;
                }

                // If the return type is a constant type...
                if (ReturnType != null && ReturnType.IsConstant())
                {
                    // ... iterate through each return statement ...
                    foreach (ReturnAction returnAction in validation.Returns)
                    {
                        // ... If the current return statement returns a value and that value does not implement the return type ...
                        if (returnAction.ReturningValue != null && (returnAction.ReturningValue.Type() == null || !returnAction.ReturningValue.Type().Implements(ReturnType)))
                        {
                            // ... then add a syntax error.
                            parseInfo.Script.Diagnostics.Error("Must return a value of type '" + ReturnType.GetName() + "'.", returnAction.ErrorRange);
                        }
                    }
                }
            }
            WasApplied = true;
            foreach (var listener in listeners)
            {
                listener.Applied();
            }
        }