private void CheckAccessLevel(OverloadMatch match)
 {
     if (!SemanticsHelper.AccessLevelMatches(match.Option.AccessLevel, match.Option.ContainingType, _parseInfo.ThisType))
     {
         _parseInfo.Script.Diagnostics.Error(string.Format("'{0}' is inaccessable due to its access level.", Overload.GetLabel(_parseInfo.TranslateInfo, LabelInfo.OverloadError)), _targetRange);
     }
 }
示例#2
0
        public ReturnAction(ParseInfo parseInfo, Scope scope, Return returnContext)
        {
            ErrorRange         = returnContext.Range;
            ReturningFromScope = scope;

            // Get the expression being returned.
            if (returnContext.Expression != null)
            {
                ReturningValue = parseInfo.SetExpectType(parseInfo.ReturnType).GetExpression(scope, returnContext.Expression);

                if (parseInfo.ReturnType != null &&
                    // Make sure that the return type matches.
                    SemanticsHelper.ExpectValueType(parseInfo, ReturningValue, parseInfo.ReturnType, returnContext.Expression.Range) &&
                    // There is a return tracker with a return handler already added.
                    parseInfo.ReturnTracker != null && parseInfo.ReturnTracker.Returns.Count > 0 &&
                    // The return type is constant.
                    parseInfo.ReturnType.IsConstant())
                {
                    // Multiple returns not allowed.
                    parseInfo.Script.Diagnostics.Error("Cannot have more than one return statement if the function's return type is constant", ErrorRange);
                }

                // returning value in void method
                else if (parseInfo.ReturnType == null)
                {
                    parseInfo.Script.Diagnostics.Error("Return type is void, no value can be returned", ErrorRange);
                }
            }
            // No return value provided, and one was expected.
            else if (parseInfo.ReturnType != null)
            {
                parseInfo.Script.Diagnostics.Error("Must return a value of type '" + parseInfo.ReturnType.GetName() + "'", returnContext.Token.Range);
            }

            parseInfo.ReturnTracker?.Add(this);
        }