예제 #1
0
 internal abstract bool AreInternalsVisibleToThisAssembly(AssemblySymbol other);
예제 #2
0
        internal ErrorTypeSymbol CreateMultipleForwardingErrorTypeSymbol(ref MetadataTypeName emittedName, ModuleSymbol forwardingModule, AssemblySymbol destination1, AssemblySymbol destination2)
        {
            var diagnosticInfo = new CSDiagnosticInfo(ErrorCode.ERR_TypeForwardedToMultipleAssemblies, forwardingModule, this, emittedName.FullName, destination1, destination2);

            return(new MissingMetadataTypeSymbol.TopLevelWithCustomErrorInfo(forwardingModule, ref emittedName, diagnosticInfo));
        }
예제 #3
0
 /// <summary>
 /// A helper method for ReferenceManager to set the system assembly, which provides primitive
 /// types like Object, String, etc., e.g. mscorlib.dll.
 /// </summary>
 internal void SetCorLibrary(AssemblySymbol corLibrary)
 {
     Debug.Assert((object)_corLibrary == null);
     _corLibrary = corLibrary;
 }
예제 #4
0
 internal static ArrayTypeSymbol CreateSZArray(
     AssemblySymbol declaringAssembly,
     TypeSymbolWithAnnotations elementType)
 {
     return(CreateSZArray(elementType, declaringAssembly.GetSpecialType(SpecialType.System_Array), GetSZArrayInterfaces(elementType, declaringAssembly)));
 }
예제 #5
0
        internal static TypeSymbol CopyTypeCustomModifiers(
            TypeSymbol sourceType,
            TypeSymbol destinationType,
            AssemblySymbol containingAssembly
            )
        {
            Debug.Assert(sourceType.Equals(destinationType, TypeCompareKind.AllIgnoreOptions));

            const RefKind refKind = RefKind.None;

            // NOTE: overrides can differ by object/dynamic, tuple element names, etc.
            // If they do, we'll need to tweak destinationType before we can use it in place of sourceType.
            // NOTE: refKind is irrelevant here since we are just encoding/decoding the type.
            ImmutableArray <bool> flags =
                CSharpCompilation.DynamicTransformsEncoder.EncodeWithoutCustomModifierFlags(
                    destinationType,
                    refKind
                    );
            TypeSymbol resultType = DynamicTypeDecoder.TransformTypeWithoutCustomModifierFlags(
                sourceType,
                containingAssembly,
                refKind,
                flags
                );

            var builder = ArrayBuilder <bool> .GetInstance();

            CSharpCompilation.NativeIntegerTransformsEncoder.Encode(builder, destinationType);
            resultType = NativeIntegerTypeDecoder.TransformType(
                resultType,
                builder.ToImmutableAndFree()
                );

            if (
                destinationType.ContainsTuple() &&
                !sourceType.Equals(
                    destinationType,
                    TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds
                    | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes
                    | TypeCompareKind.IgnoreDynamic
                    )
                )
            {
                // We also preserve tuple names, if present and different
                ImmutableArray <string> names = CSharpCompilation.TupleNamesEncoder.Encode(
                    destinationType
                    );
                resultType = TupleTypeDecoder.DecodeTupleTypesIfApplicable(resultType, names);
            }

            // Preserve nullable modifiers as well.
            // https://github.com/dotnet/roslyn/issues/30077: Is it reasonable to copy annotations from the source?
            // If the destination had some of those annotations but not all, then clearly the destination
            // was incorrect. Or if the destination is C#7, then the destination will advertise annotations
            // that the author did not write and did not validate.
            var flagsBuilder = ArrayBuilder <byte> .GetInstance();

            destinationType.AddNullableTransforms(flagsBuilder);
            int  position        = 0;
            int  length          = flagsBuilder.Count;
            bool transformResult = resultType.ApplyNullableTransforms(
                defaultTransformFlag: 0,
                flagsBuilder.ToImmutableAndFree(),
                ref position,
                out resultType
                );

            Debug.Assert(transformResult && position == length);

            Debug.Assert(
                resultType.Equals(
                    sourceType,
                    TypeCompareKind.IgnoreDynamicAndTupleNames
                    | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes
                    | TypeCompareKind.IgnoreNativeIntegers
                    )
                ); // Same custom modifiers as source type.

            // Same object/dynamic, nullability, native integers, and tuple names as destination type.
            Debug.Assert(
                resultType.Equals(
                    destinationType,
                    TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds
                    )
                );

            return(resultType);
        }
예제 #6
0
        protected static void CopyEventCustomModifiers(EventSymbol eventWithCustomModifiers, ref TypeSymbol type, AssemblySymbol containingAssembly)
        {
            Debug.Assert((object)eventWithCustomModifiers != null);

            TypeSymbol overriddenEventType = eventWithCustomModifiers.Type;

            // We do an extra check before copying the type to handle the case where the overriding
            // event (incorrectly) has a different type than the overridden event.  In such cases,
            // we want to retain the original (incorrect) type to avoid hiding the type given in source.
            if (type.Equals(overriddenEventType, TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds | TypeCompareKind.IgnoreDynamic))
            {
                type = CustomModifierUtils.CopyTypeCustomModifiers(overriddenEventType, type, containingAssembly);
            }
        }
 internal override bool AreInternalsVisibleToThisAssembly(AssemblySymbol other)
 {
     return(false);
 }
예제 #8
0
 internal NamespaceExtent(AssemblySymbol assembly)
 {
     _kind = NamespaceKind.Assembly;
     _symbolOrCompilation = assembly;
 }
예제 #9
0
        /// <param name="sourceType">Type that already has custom modifiers.</param>
        /// <param name="destinationType">Same as <paramref name="sourceType"/>, but without custom modifiers.  May differ in object/dynamic.</param>
        /// <param name="containingAssembly">The assembly containing the signature referring to the destination type.</param>
        /// <returns><paramref name="destinationType"/> with custom modifiers copied from <paramref name="sourceType"/>.</returns>
        internal static TypeSymbol CopyTypeCustomModifiers(TypeSymbol sourceType, TypeSymbol destinationType, AssemblySymbol containingAssembly)
        {
            Debug.Assert(sourceType.Equals(destinationType, TypeCompareKind.AllIgnoreOptions));

            // NOTE: overrides can differ by object/dynamic.  If they do, we'll need to tweak newType before
            // we can use it in place of this.Type.  We do so by computing the dynamic transform flags that
            // code gen uses and then passing them to the dynamic type decoder that metadata reading uses.
            // NOTE: ref is irrelevant here since we are just encoding/decoding the type out of the signature context
            ImmutableArray <bool> flags           = CSharpCompilation.DynamicTransformsEncoder.EncodeWithoutCustomModifierFlags(destinationType, RefKind.None);
            TypeSymbol            typeWithDynamic = DynamicTypeDecoder.TransformTypeWithoutCustomModifierFlags(sourceType, containingAssembly, RefKind.None, flags);

            TypeSymbol resultType;

            if (destinationType.ContainsTuple() && !sourceType.Equals(destinationType, TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds | TypeCompareKind.IgnoreDynamic))
            {
                // We also preserve tuple names, if present and different
                ImmutableArray <string> names = CSharpCompilation.TupleNamesEncoder.Encode(destinationType);
                resultType = TupleTypeDecoder.DecodeTupleTypesIfApplicable(typeWithDynamic, names);
            }
            else
            {
                resultType = typeWithDynamic;
            }

            Debug.Assert(resultType.Equals(sourceType, TypeCompareKind.IgnoreDynamicAndTupleNames));                            // Same custom modifiers as source type.
            Debug.Assert(resultType.Equals(destinationType, TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds)); // Same object/dynamic and tuple names as destination type.
            return(resultType);
        }
예제 #10
0
        // Based on SymbolLoader::ResolveBounds.
        public static TypeParameterBounds ResolveBounds(
            this TypeParameterSymbol typeParameter,
            AssemblySymbol corLibrary,
            ConsList <TypeParameterSymbol> inProgress,
            ImmutableArray <TypeSymbol> constraintTypes,
            bool inherited,
            CSharpCompilation currentCompilation,
            ArrayBuilder <TypeParameterDiagnosticInfo> diagnosticsBuilder,
            ref ArrayBuilder <TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder)
        {
            Debug.Assert(currentCompilation == null || typeParameter.IsFromCompilation(currentCompilation));

            ImmutableArray <NamedTypeSymbol> interfaces;

            NamedTypeSymbol   effectiveBaseClass = corLibrary.GetSpecialType(typeParameter.HasValueTypeConstraint ? SpecialType.System_ValueType : SpecialType.System_Object);
            TypeSymbol        deducedBaseType    = effectiveBaseClass;
            DynamicTypeEraser dynamicEraser      = null;

            if (constraintTypes.Length == 0)
            {
                interfaces = ImmutableArray <NamedTypeSymbol> .Empty;
            }
            else
            {
                var constraintTypesBuilder = ArrayBuilder <TypeSymbol> .GetInstance();

                var interfacesBuilder = ArrayBuilder <NamedTypeSymbol> .GetInstance();

                var conversions = new TypeConversions(corLibrary);
                HashSet <DiagnosticInfo> useSiteDiagnostics = null;

                // Resolve base types, determine the effective base class and
                // interfaces, and filter out any constraint types that cause cycles.
                foreach (var constraintType in constraintTypes)
                {
                    NamedTypeSymbol constraintEffectiveBase;
                    TypeSymbol      constraintDeducedBase;

                    switch (constraintType.TypeKind)
                    {
                    case TypeKind.Dynamic:
                        Debug.Assert(inherited || currentCompilation == null);
                        continue;

                    case TypeKind.TypeParameter:
                    {
                        var containingSymbol        = typeParameter.ContainingSymbol;
                        var constraintTypeParameter = (TypeParameterSymbol)constraintType;
                        ConsList <TypeParameterSymbol> constraintsInProgress;

                        if (constraintTypeParameter.ContainingSymbol == containingSymbol)
                        {
                            // The constraint type parameter is from the same containing type or method.
                            if (inProgress.ContainsReference(constraintTypeParameter))
                            {
                                // "Circular constraint dependency involving '{0}' and '{1}'"
                                diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(constraintTypeParameter, new CSDiagnosticInfo(ErrorCode.ERR_CircularConstraint, constraintTypeParameter, typeParameter)));
                                continue;
                            }

                            constraintsInProgress = inProgress;
                        }
                        else
                        {
                            // The constraint type parameter is from a different containing symbol so no cycle.
                            constraintsInProgress = ConsList <TypeParameterSymbol> .Empty;
                        }

                        // Use the calculated bounds from the constraint type parameter.
                        constraintEffectiveBase = constraintTypeParameter.GetEffectiveBaseClass(constraintsInProgress);
                        constraintDeducedBase   = constraintTypeParameter.GetDeducedBaseType(constraintsInProgress);
                        AddInterfaces(interfacesBuilder, constraintTypeParameter.GetInterfaces(constraintsInProgress));

                        if (constraintTypeParameter.HasValueTypeConstraint && !inherited && currentCompilation != null && constraintTypeParameter.IsFromCompilation(currentCompilation))
                        {
                            // "Type parameter '{1}' has the 'struct' constraint so '{1}' cannot be used as a constraint for '{0}'"
                            diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new CSDiagnosticInfo(ErrorCode.ERR_ConWithValCon, typeParameter, constraintTypeParameter)));
                            continue;
                        }
                    }
                    break;

                    case TypeKind.Interface:
                    case TypeKind.Class:
                    case TypeKind.Delegate:
                        NamedTypeSymbol erasedConstraintType;

                        if (inherited || currentCompilation == null)
                        {
                            // only inherited constraints may contain dynamic
                            if (dynamicEraser == null)
                            {
                                dynamicEraser = new DynamicTypeEraser(corLibrary.GetSpecialType(SpecialType.System_Object));
                            }

                            erasedConstraintType = (NamedTypeSymbol)dynamicEraser.EraseDynamic(constraintType);
                        }
                        else
                        {
                            Debug.Assert(!constraintType.ContainsDynamic());
                            Debug.Assert(constraintType.TypeKind != TypeKind.Delegate);

                            erasedConstraintType = (NamedTypeSymbol)constraintType;
                        }

                        if (constraintType.IsInterfaceType())
                        {
                            AddInterface(interfacesBuilder, erasedConstraintType);
                            constraintTypesBuilder.Add(constraintType);
                            continue;
                        }
                        else
                        {
                            constraintEffectiveBase = erasedConstraintType;
                            constraintDeducedBase   = constraintType;
                            break;
                        }

                    case TypeKind.Struct:
                        Debug.Assert(inherited || currentCompilation == null);
                        constraintEffectiveBase = corLibrary.GetSpecialType(SpecialType.System_ValueType);
                        constraintDeducedBase   = constraintType;
                        break;

                    case TypeKind.Enum:
                        Debug.Assert(inherited || currentCompilation == null);
                        constraintEffectiveBase = corLibrary.GetSpecialType(SpecialType.System_Enum);
                        constraintDeducedBase   = constraintType;
                        break;

                    case TypeKind.Array:
                        Debug.Assert(inherited || currentCompilation == null);
                        constraintEffectiveBase = corLibrary.GetSpecialType(SpecialType.System_Array);
                        constraintDeducedBase   = constraintType;
                        break;

                    case TypeKind.Error:
                        constraintEffectiveBase = (NamedTypeSymbol)constraintType;
                        constraintDeducedBase   = constraintType;
                        break;

                    case TypeKind.Submission:
                    default:
                        throw ExceptionUtilities.UnexpectedValue(constraintType.TypeKind);
                    }

                    CheckEffectiveAndDeducedBaseTypes(conversions, constraintEffectiveBase, constraintDeducedBase);

                    constraintTypesBuilder.Add(constraintType);

                    // Determine the more encompassed of the current effective base
                    // class and the previously computed effective base class.
                    if (!deducedBaseType.IsErrorType() && !constraintDeducedBase.IsErrorType())
                    {
                        if (!IsEncompassedBy(conversions, deducedBaseType, constraintDeducedBase, ref useSiteDiagnostics))
                        {
                            if (!IsEncompassedBy(conversions, constraintDeducedBase, deducedBaseType, ref useSiteDiagnostics))
                            {
                                // "Type parameter '{0}' inherits conflicting constraints '{1}' and '{2}'"
                                diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new CSDiagnosticInfo(ErrorCode.ERR_BaseConstraintConflict, typeParameter, constraintDeducedBase, deducedBaseType)));
                            }
                            else
                            {
                                deducedBaseType    = constraintDeducedBase;
                                effectiveBaseClass = constraintEffectiveBase;
                            }
                        }
                    }
                }

                AppendUseSiteDiagnostics(useSiteDiagnostics, typeParameter, ref useSiteDiagnosticsBuilder);

                CheckEffectiveAndDeducedBaseTypes(conversions, effectiveBaseClass, deducedBaseType);

                constraintTypes = constraintTypesBuilder.ToImmutableAndFree();
                interfaces      = interfacesBuilder.ToImmutableAndFree();
            }

            Debug.Assert((effectiveBaseClass.SpecialType == SpecialType.System_Object) || (deducedBaseType.SpecialType != SpecialType.System_Object));

            // Only create a TypeParameterBounds instance for this type
            // parameter if the bounds are not the default values.
            if ((constraintTypes.Length == 0) && (deducedBaseType.SpecialType == SpecialType.System_Object))
            {
                Debug.Assert(effectiveBaseClass.SpecialType == SpecialType.System_Object);
                Debug.Assert(interfaces.Length == 0);
                return(null);
            }

            var bounds = new TypeParameterBounds(constraintTypes, interfaces, effectiveBaseClass, deducedBaseType);

            // Additional constraint checks for overrides.
            if (inherited)
            {
                CheckOverrideConstraints(typeParameter, bounds, diagnosticsBuilder);
            }

            return(bounds);
        }
예제 #11
0
        /// <param name="sourceType">Type that already has custom modifiers.</param>
        /// <param name="destinationType">Same as <paramref name="sourceType"/>, but without custom modifiers.  May differ in object/dynamic.</param>
        /// <param name="refKind"><see cref="RefKind"/> of the parameter of which this is the type (or <see cref="RefKind.None"/> for a return type.</param>
        /// <param name="containingAssembly">The assembly containing the signature referring to the destination type.</param>
        /// <returns><paramref name="destinationType"/> with custom modifiers copied from <paramref name="sourceType"/>.</returns>
        internal static TypeSymbol CopyTypeCustomModifiers(TypeSymbol sourceType, TypeSymbol destinationType, RefKind refKind, AssemblySymbol containingAssembly)
        {
            Debug.Assert(sourceType.Equals(destinationType, ignoreCustomModifiers: true, ignoreDynamic: true));

            // NOTE: overrides can differ by object/dynamic.  If they do, we'll need to tweak newType before
            // we can use it in place of this.Type.  We do so by computing the dynamic transform flags that
            // code gen uses and then passing them to the dynamic type decoder that metadata reading uses.

            const int             customModifierCount = 0;// Ignore custom modifiers, since we're not done copying them.
            ImmutableArray <bool> flags      = CSharpCompilation.DynamicTransformsEncoder.Encode(destinationType, customModifierCount, refKind);
            TypeSymbol            resultType = DynamicTypeDecoder.TransformTypeWithoutCustomModifierFlags(sourceType, containingAssembly, refKind, flags);

            Debug.Assert(resultType.Equals(sourceType, ignoreCustomModifiers: false, ignoreDynamic: true));      // Same custom modifiers as source type.
            Debug.Assert(resultType.Equals(destinationType, ignoreCustomModifiers: true, ignoreDynamic: false)); // Same object/dynamic as destination type.

            return(resultType);
        }
예제 #12
0
        internal NamedTypeSymbol GetTopLevelTypeByMetadataName(
            ref MetadataTypeName metadataName,
            AssemblyIdentity assemblyOpt,
            bool includeReferences,
            bool isWellKnownType,
            out (AssemblySymbol, AssemblySymbol) conflicts,
            DiagnosticBag warnings = null,
            bool ignoreCorLibraryDuplicatedTypes = false)
        {
            conflicts = default;
            NamedTypeSymbol result;

            // First try this assembly
            result = GetTopLevelTypeByMetadataName(this, ref metadataName, assemblyOpt);

            if (isWellKnownType && !IsValidWellKnownType(result))
            {
                result = null;
            }

            // ignore any types of the same name that might be in referenced assemblies (prefer the current assembly):
            if ((object)result != null || !includeReferences)
            {
                return(result);
            }

            Debug.Assert(this is SourceAssemblySymbol,
                         "Never include references for a non-source assembly, because they don't know about aliases.");

            var assemblies = ArrayBuilder <AssemblySymbol> .GetInstance();

            // ignore reference aliases if searching for a type from a specific assembly:
            if (assemblyOpt != null)
            {
                assemblies.AddRange(DeclaringCompilation.GetBoundReferenceManager().ReferencedAssemblies);
            }
            else
            {
                DeclaringCompilation.GetUnaliasedReferencedAssemblies(assemblies);
            }

            // Lookup in references
            foreach (var assembly in assemblies)
            {
                Debug.Assert(!(this is SourceAssemblySymbol && assembly.IsMissing)); // Non-source assemblies can have missing references

                NamedTypeSymbol candidate = GetTopLevelTypeByMetadataName(assembly, ref metadataName, assemblyOpt);

                if (isWellKnownType && !IsValidWellKnownType(candidate))
                {
                    candidate = null;
                }

                if ((object)candidate == null)
                {
                    continue;
                }

                if (candidate.IsHiddenByCodeAnalysisEmbeddedAttribute())
                {
                    continue;
                }

                Debug.Assert(!TypeSymbol.Equals(candidate, result, TypeCompareKind.ConsiderEverything2));

                if ((object)result != null)
                {
                    // duplicate
                    if (ignoreCorLibraryDuplicatedTypes)
                    {
                        if (IsInCorLib(candidate))
                        {
                            // ignore candidate
                            continue;
                        }
                        if (IsInCorLib(result))
                        {
                            // drop previous result
                            result = candidate;
                            continue;
                        }
                    }

                    if (warnings == null)
                    {
                        conflicts = (result.ContainingAssembly, candidate.ContainingAssembly);
                        result    = null;
                    }
                    else
                    {
                        // The predefined type '{0}' is defined in multiple assemblies in the global alias; using definition from '{1}'
                        warnings.Add(ErrorCode.WRN_MultiplePredefTypes, NoLocation.Singleton, result, result.ContainingAssembly);
                    }

                    break;
                }

                result = candidate;
            }

            assemblies.Free();
            return(result);
        }
예제 #13
0
        /// <param name="sourceType">Type that already has custom modifiers.</param>
        /// <param name="destinationType">Same as <paramref name="sourceType"/>, but without custom modifiers.  May differ in object/dynamic.</param>
        /// <param name="containingAssembly">The assembly containing the signature referring to the destination type.</param>
        /// <param name="nonNullTypesContext">The NonNullTypes context at the destination.</param>
        /// <returns><paramref name="destinationType"/> with custom modifiers copied from <paramref name="sourceType"/>.</returns>
        internal static TypeSymbol CopyTypeCustomModifiers(TypeSymbol sourceType, TypeSymbol destinationType, AssemblySymbol containingAssembly, INonNullTypesContext nonNullTypesContext)
        {
            Debug.Assert(sourceType.Equals(destinationType, TypeCompareKind.AllIgnoreOptions));
            Debug.Assert(nonNullTypesContext != null);

            const RefKind refKind = RefKind.None;

            // NOTE: overrides can differ by object/dynamic.  If they do, we'll need to tweak newType before
            // we can use it in place of this.Type.  We do so by computing the dynamic transform flags that
            // code gen uses and then passing them to the dynamic type decoder that metadata reading uses.
            // NOTE: ref is irrelevant here since we are just encoding/decoding the type out of the signature context
            ImmutableArray <bool> flags           = CSharpCompilation.DynamicTransformsEncoder.EncodeWithoutCustomModifierFlags(destinationType, refKind);
            TypeSymbol            typeWithDynamic = DynamicTypeDecoder.TransformTypeWithoutCustomModifierFlags(sourceType, containingAssembly, refKind, flags);

            TypeSymbol resultType;

            if (destinationType.ContainsTuple() && !sourceType.Equals(destinationType, TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes | TypeCompareKind.IgnoreDynamic))
            {
                // We also preserve tuple names, if present and different
                ImmutableArray <string> names = CSharpCompilation.TupleNamesEncoder.Encode(destinationType);
                resultType = TupleTypeDecoder.DecodeTupleTypesIfApplicable(typeWithDynamic, names);
            }
            else
            {
                resultType = typeWithDynamic;
            }

            // Preserve nullable modifiers as well.
            // https://github.com/dotnet/roslyn/issues/30077: Is it reasonable to copy annotations from the source?
            // If the destination had some of those annotations but not all, then clearly the destination
            // was incorrect. Or if the destination is C#7, then the destination will advertise annotations
            // that the author did not write and did not validate.
            var flagsBuilder = ArrayBuilder <bool> .GetInstance();

            destinationType.AddNullableTransforms(flagsBuilder);
            int  position        = 0;
            int  length          = flagsBuilder.Count;
            bool transformResult = resultType.ApplyNullableTransforms(flagsBuilder.ToImmutableAndFree(), nonNullTypesContext, ref position, out resultType);

            Debug.Assert(transformResult && position == length);

            Debug.Assert(resultType.Equals(sourceType, TypeCompareKind.IgnoreDynamicAndTupleNames | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes)); // Same custom modifiers as source type.

            Debug.Assert(resultType.Equals(destinationType,
                                           TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes)); // Same object/dynamic and tuple names as destination type.

            return(resultType);
        }
예제 #14
0
        protected static void CopyEventCustomModifiers(EventSymbol eventWithCustomModifiers, ref TypeSymbolWithAnnotations type, AssemblySymbol containingAssembly, Symbol nonNullTypesContext)
        {
            Debug.Assert((object)eventWithCustomModifiers != null);
            Debug.Assert(nonNullTypesContext != null);

            TypeSymbol overriddenEventType = eventWithCustomModifiers.Type.TypeSymbol;

            // We do an extra check before copying the type to handle the case where the overriding
            // event (incorrectly) has a different type than the overridden event.  In such cases,
            // we want to retain the original (incorrect) type to avoid hiding the type given in source.
            if (type.TypeSymbol.Equals(overriddenEventType, TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes | TypeCompareKind.IgnoreDynamic))
            {
                type = type.WithTypeAndModifiers(CustomModifierUtils.CopyTypeCustomModifiers(overriddenEventType, type.TypeSymbol, containingAssembly, nonNullTypesContext),
                                                 eventWithCustomModifiers.Type.CustomModifiers);
            }
        }