internal void ComputeReturnType() { if (!_lazyReturnType.IsNull) { return; } var diagnostics = DiagnosticBag.GetInstance(); TypeSyntax returnTypeSyntax = _syntax.ReturnType; TypeSymbolWithAnnotations returnType = _binder.BindType(returnTypeSyntax, diagnostics); if (this.IsAsync) { if (this.RefKind != RefKind.None) { ReportBadRefToken(returnTypeSyntax, diagnostics); } else if (returnType.TypeSymbol.IsBadAsyncReturn(this.DeclaringCompilation)) { diagnostics.Add(ErrorCode.ERR_BadAsyncReturn, this.Locations[0]); } } var location = _syntax.ReturnType.Location; if (_refKind == RefKind.RefReadOnly) { DeclaringCompilation.EnsureIsReadOnlyAttributeExists(diagnostics, location, modifyCompilation: false); } if (returnType.NeedsNullableAttribute()) { DeclaringCompilation.EnsureNullableAttributeExists(diagnostics, location, modifyCompilation: false); // Note: we don't need to warn on annotations used without NonNullTypes context for local functions, as this is handled in binding already } // span-like types are returnable in general if (returnType.IsRestrictedType(ignoreSpanLikeTypes: true)) { // Method or delegate cannot return type '{0}' diagnostics.Add(ErrorCode.ERR_MethodReturnCantBeRefAny, returnTypeSyntax.Location, returnType.TypeSymbol); } Debug.Assert(_refKind == RefKind.None || returnType.SpecialType != SpecialType.System_Void || returnTypeSyntax.HasErrors); lock (_declarationDiagnostics) { if (!_lazyReturnType.IsNull) { diagnostics.Free(); return; } _declarationDiagnostics.AddRangeAndFree(diagnostics); _lazyReturnType = returnType; } }