private void GetInitialValue()
        {
            // Get the initial value.
            if (_initalValueContext != null)
            {
                ParseInfo parseInfo = this.parseInfo;

                // Store the initial value's restricted calls.
                RestrictedCallList restrictedCalls = null;
                if (_handleRestrictedCalls)
                {
                    restrictedCalls = new RestrictedCallList();
                    parseInfo       = parseInfo.SetRestrictedCallHandler(restrictedCalls);
                }

                // Parse the initial value.
                InitialValue = parseInfo.GetExpression(_operationalScope, _initalValueContext);
                if (InitialValue?.Type() != null && InitialValue.Type().IsConstant() && !InitialValue.Type().Implements(CodeType))
                {
                    parseInfo.Script.Diagnostics.Error($"The type '{InitialValue.Type().Name}' cannot be stored.", DocRange.GetRange(_initalValueContext));
                }

                // Check restricted calls.
                if (_handleRestrictedCalls)
                {
                    foreach (RestrictedCall call in restrictedCalls)
                    {
                        // If the variable type is global, or the variable type is player and the restricted call type is not player...
                        if (VariableType == VariableType.Global ||
                            (VariableType == VariableType.Player && call.CallType != RestrictedCallType.EventPlayer))
                        {
                            // ... then add the error.
                            parseInfo.Script.Diagnostics.Error(call.Message, call.CallRange.range);
                        }
                    }
                }
            }
        }
        private void GetInitialValue()
        {
            // Get the initial value.
            if (_initialValueContext != null)
            {
                ParseInfo parseInfo = this._parseInfo;

                // Store the initial value's restricted calls.
                RestrictedCallList restrictedCalls = null;
                if (_handleRestrictedCalls)
                {
                    restrictedCalls = new RestrictedCallList();
                    parseInfo       = parseInfo.SetRestrictedCallHandler(restrictedCalls);
                }

                ParseInfo initialValueParseInfo = parseInfo.SetExpectType(CodeType);
                if (parseInfo.CurrentCallInfo == null)
                {
                    CallInfo callInfo = new CallInfo(parseInfo.Script);
                    initialValueParseInfo = initialValueParseInfo.SetCallInfo(callInfo);
                }

                // Parse the initial value.
                InitialValue = initialValueParseInfo.GetExpression(_operationalScope, _initialValueContext);

                // Get the inferred type.
                if (_inferType)
                {
                    CodeType = InitialValue.Type();
                    _variableTypeHandler.SetType(CodeType);
                    AddScriptData();
                }

                // If the initial value's type is constant, make sure the constant type's implements the variable's type.
                if (InitialValue?.Type() != null && InitialValue.Type().IsConstant() && !InitialValue.Type().Implements(CodeType))
                {
                    parseInfo.Script.Diagnostics.Error($"The type '{InitialValue.Type().Name}' cannot be stored.", _initialValueContext.Range);
                }

                // If the variable's type is constant, make sure the value's type matches.
                else
                {
                    SemanticsHelper.ExpectValueType(parseInfo, InitialValue, CodeType, _initialValueContext.Range);
                }

                // Check restricted calls.
                if (_handleRestrictedCalls)
                {
                    foreach (RestrictedCall call in restrictedCalls)
                    {
                        // If the variable type is global, or the variable type is player and the restricted call type is not player...
                        if (VariableType == VariableType.Global ||
                            (VariableType == VariableType.Player && call.CallType != RestrictedCallType.EventPlayer))
                        {
                            // ... then add the error.
                            call.AddDiagnostic(parseInfo.Script.Diagnostics);
                        }
                    }
                }
            }

            ValueReady.Set();
        }