Exemple #1
0
 public void Applied()
 {
     if (UsedAsExpression && !CallingMethod.DoesReturnValue())
     {
         parseInfo.Script.Diagnostics.Error("The chosen overload for " + CallingMethod.Name + " does not return a value.", NameRange);
     }
 }
Exemple #2
0
        public CallMethodAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.MethodContext methodContext, bool usedAsExpression, Scope getter)
        {
            this.translateInfo = parseInfo.TranslateInfo;
            string methodName = methodContext.PART().GetText();

            NameRange = DocRange.GetRange(methodContext.PART());

            var options = scope.GetMethodsByName(methodName);

            if (options.Length == 0)
            {
                parseInfo.Script.Diagnostics.Error($"No method by the name of '{methodName}' exists in the current context.", NameRange);
            }
            else
            {
                OverloadChooser = new OverloadChooser(options, parseInfo, getter, NameRange, DocRange.GetRange(methodContext), new OverloadError("method '" + methodName + "'"));

                if (methodContext.call_parameters() != null)
                {
                    OverloadChooser.SetContext(methodContext.call_parameters());
                }
                else if (methodContext.picky_parameters() != null)
                {
                    OverloadChooser.SetContext(methodContext.picky_parameters());
                }
                else
                {
                    OverloadChooser.SetContext();
                }

                CallingMethod   = (IMethod)OverloadChooser.Overload;
                ParameterValues = OverloadChooser.Values;

                if (CallingMethod != null)
                {
                    if (CallingMethod is DefinedFunction)
                    {
                        var definedFunction = (DefinedFunction)CallingMethod;
                        definedFunction.Call(parseInfo.Script, NameRange);
                        parseInfo.CurrentCallInfo?.Call(definedFunction, NameRange);
                    }

                    parseInfo.Script.AddHover(DocRange.GetRange(methodContext), CallingMethod.GetLabel(true));

                    if (usedAsExpression && !CallingMethod.DoesReturnValue())
                    {
                        parseInfo.Script.Diagnostics.Error("The chosen overload for " + methodName + " does not return a value.", NameRange);
                    }
                }
            }
        }