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

Code before:

            for (int i = 0; i < baseParameters.Length; i++)
            {
                var baseParameter = baseParameters[i];
                var overrideParameter = overrideParameters[i + overrideParameterOffset];
                if (baseParameter.RefKind != overrideParameter.RefKind)
                {
                    reportMismatchInParameterType(diagnostics, baseMethod, overrideMethod, overrideParameter, topLevel: true, (baseParameter, extraArgument));
                }
            }
        }

        internal static void CheckCallerUnsafeMismatch<TArg>(
            Symbol? overriddenMember,
            Symbol? overridingMember,
            ErrorCode errorCode,
            TArg arg,
            Func<TArg, Location> overridingMemberLocation,
            BindingDiagnosticBag diagnostics)
        {
            if (overriddenMember is null || overridingMember is null)
            {
                return;
            }

            overriddenMember = overriddenMember.OriginalDefinition;
            var leastOverriddenMember = overriddenMember.GetLeastOverriddenMember(overriddenMember.ContainingType);
            if (overridingMember.CallerUnsafeMode == CallerUnsafeMode.Explicit && leastOverriddenMember.CallerUnsafeMode == CallerUnsafeMode.None)
            {
                diagnostics.Add(errorCode, overridingMemberLocation(arg), overridingMember, leastOverriddenMember);
            }
        }
#nullable disable

        private static bool PerformValidNullableOverrideCheck(
            CSharpCompilation compilation,
            Symbol overriddenMember,
            Symbol overridingMember)
        {
            // Don't do any validation if the nullable feature is not enabled or
            // the override is not written directly in source
            return overriddenMember is object &&
                   overridingMember is object &&
                   compilation is object &&
                   compilation.IsFeatureEnabled(MessageID.IDS_FeatureNullableReferenceTypes);
        }

        internal static void CheckValidNullableEventOverride<TArg>(
            CSharpCompilation compilation,
            EventSymbol overriddenEvent,
            EventSymbol overridingEvent,

Review comment (suggestion):
I didn't quite understand exactly what the problem was. How did the logic below trigger an IVT check and why was that check inappropriate? It seems fair game to ask questions about `overriddenMember` and `leastOverriddenMember` since we're referencing them. #Closed

Code after:

            for (int i = 0; i < baseParameters.Length; i++)
            {
                var baseParameter = baseParameters[i];
                var overrideParameter = overrideParameters[i + overrideParameterOffset];
                if (baseParameter.RefKind != overrideParameter.RefKind)
                {
                    reportMismatchInParameterType(diagnostics, baseMethod, overrideMethod, overrideParameter, topLevel: true, (baseParameter, extraArgument));
                }
            }
        }

        internal static void CheckCallerUnsafeMismatch<TArg>(
            Symbol? implementedMember,
            Symbol? overridingMember,
            ErrorCode errorCode,
            TArg arg,
            Func<TArg, Location> overridingMemberLocation,
            BindingDiagnosticBag diagnostics)
        {
            if (overridingMember is null)
            {
                return;
            }

            Debug.Assert(implementedMember is not null || overridingMember.IsDefinition);

            var leastOverriddenMember = implementedMember ?? overridingMember.GetLeastOverriddenMember(overridingMember.ContainingType);
            if (overridingMember.CallerUnsafeMode == CallerUnsafeMode.Explicit && leastOverriddenMember.CallerUnsafeMode == CallerUnsafeMode.None)
            {
                diagnostics.Add(errorCode, overridingMemberLocation(arg), overridingMember, leastOverriddenMember);
            }
        }
#nullable disable

        private static bool PerformValidNullableOverrideCheck(
            CSharpCompilation compilation,
            Symbol overriddenMember,
            Symbol overridingMember)
        {
            // Don't do any validation if the nullable feature is not enabled or
            // the override is not written directly in source
            return overriddenMember is object &&
                   overridingMember is object &&
                   compilation is object &&
                   compilation.IsFeatureEnabled(MessageID.IDS_FeatureNullableReferenceTypes);
        }

        internal static void CheckValidNullableEventOverride<TArg>(
            CSharpCompilation compilation,
            EventSymbol overriddenEvent,