/// <summary> /// Determine the constant value of this local and the corresponding diagnostics. /// Set both to constantTuple in a single operation for thread safety. /// </summary> /// <param name="inProgress">Null for the initial call, non-null if we are in the process of evaluating a constant.</param> /// <param name="boundInitValue">If we already have the bound node for the initial value, pass it in to avoid recomputing it.</param> private void MakeConstantTuple(LocalSymbol inProgress, BoundExpression boundInitValue) { if (this.IsConst && _constantTuple == null) { var value = Microsoft.CodeAnalysis.ConstantValue.Bad; var initValueNodeLocation = _initializer.Value.Location; var diagnostics = DiagnosticBag.GetInstance(); Debug.Assert(inProgress != this); var type = this.Type; if (boundInitValue == null) { var inProgressBinder = new LocalInProgressBinder(this, this._initializerBinder); boundInitValue = inProgressBinder.BindVariableOrAutoPropInitializerValue(_initializer, this.RefKind, type, diagnostics); } value = ConstantValueUtils.GetAndValidateConstantValue(boundInitValue, this, type, initValueNodeLocation, diagnostics); Interlocked.CompareExchange(ref _constantTuple, new EvaluatedConstant(value, diagnostics.ToReadOnlyAndFree()), null); } }