Repository: dotnet/roslyn
File: src/Compilers/CSharp/Portable/Symbols/AnonymousTypes/AnonymousTypeManager.cs (C#)

Code before:
using System.Diagnostics;
using Microsoft.CodeAnalysis.Symbols;

namespace Microsoft.CodeAnalysis.CSharp.Symbols
{
    /// <summary>
    /// Manages anonymous types created in owning compilation. All requests for 
    /// anonymous type symbols go via the instance of this class.
    /// </summary>
    internal sealed partial class AnonymousTypeManager : CommonAnonymousTypeManager
    {
        internal AnonymousTypeManager(CSharpCompilation compilation)
        {
            Debug.Assert(compilation != null);
            this.Compilation = compilation;
        }

        /// <summary> 
        /// Current compilation
        /// </summary>
        public CSharpCompilation Compilation { get; }

        /// <summary>
        /// Given anonymous type descriptor provided constructs an anonymous type symbol.
        /// </summary>
        public NamedTypeSymbol ConstructAnonymousTypeSymbol(AnonymousTypeDescriptor typeDescr, BindingDiagnosticBag diagnostics)
        {
            if (diagnostics.AccumulatesDependencies)
            {
                var depencies = BindingDiagnosticBag.GetInstance(withDependencies: true, withDiagnostics: false);
                ReportMissingOrErroneousSymbols(depencies);
                diagnostics.AddRange(depencies);
                depencies.Free();
            }

            return new AnonymousTypePublicSymbol(this, typeDescr);
        }

        public NamedTypeSymbol ConstructAnonymousDelegateSymbol(AnonymousTypeDescriptor typeDescr)
        {
            // ReportMissingOrErroneousSymbols is not reporting anything for delegate types and
            // ReportMissingOrErroneousSymbolsForDelegates reports only Special types.
            // Therefore, we have no additional dependencies to report here.
            return new AnonymousDelegatePublicSymbol(this, typeDescr);
        }

        /// <summary>
        /// Get a symbol of constructed anonymous type property by property index
        /// </summary>
        internal static PropertySymbol GetAnonymousTypeProperty(NamedTypeSymbol type, int index)
        {

Review comment (suggestion):
Consider renaming `diagnostics` or adding a doc comment, so it's clearer at the callsites that it's only used to collect dependencies (and hence why it's fine to pass `BindingDiagnosticBag.Discarded` sometimes) #Resolved

Code after:
using System.Diagnostics;
using Microsoft.CodeAnalysis.Symbols;

namespace Microsoft.CodeAnalysis.CSharp.Symbols
{
    /// <summary>
    /// Manages anonymous types created in owning compilation. All requests for 
    /// anonymous type symbols go via the instance of this class.
    /// </summary>
    internal sealed partial class AnonymousTypeManager : CommonAnonymousTypeManager
    {
        internal AnonymousTypeManager(CSharpCompilation compilation)
        {
            Debug.Assert(compilation != null);
            this.Compilation = compilation;
        }

        /// <summary> 
        /// Current compilation
        /// </summary>
        public CSharpCompilation Compilation { get; }

        /// <summary>
        /// Given anonymous type descriptor provided constructs an anonymous type symbol.
        /// </summary>
        public NamedTypeSymbol ConstructAnonymousTypeSymbol(AnonymousTypeDescriptor typeDescr, BindingDiagnosticBag diagnostics)
        {
            if (diagnostics.AccumulatesDependencies)
            {
                var dependencies = BindingDiagnosticBag.GetInstance(withDependencies: true, withDiagnostics: false);
                ReportMissingOrErroneousSymbols(dependencies);
                diagnostics.AddRange(dependencies);
                dependencies.Free();
            }

            return new AnonymousTypePublicSymbol(this, typeDescr);
        }

        public NamedTypeSymbol ConstructAnonymousDelegateSymbol(AnonymousTypeDescriptor typeDescr)
        {
            // ReportMissingOrErroneousSymbols is not reporting anything for delegate types and
            // ReportMissingOrErroneousSymbolsForDelegates reports only Special types.
            // Therefore, we have no additional dependencies to report here.
            return new AnonymousDelegatePublicSymbol(this, typeDescr);
        }

        /// <summary>
        /// Get a symbol of constructed anonymous type property by property index
        /// </summary>
        internal static PropertySymbol GetAnonymousTypeProperty(NamedTypeSymbol type, int index)
        {