Skip to content

Overriding method with [MaybeNull, NottNullWhen(true)] produces a warning #42169

@jcouv

Description

@jcouv

I encountered this in DiagnosticStartAnalysisScope.cs at line 203 (method TryGetValueCore).

using System;
using System.Diagnostics.CodeAnalysis;
#nullable enable

public class C {
         internal virtual bool TryGetValueCore<TKey, TValue>(TKey key, string valueProvider, [MaybeNull] [NotNullWhen(true)] out TValue value)
            where TKey : class
        {
            throw new NotImplementedException();
        }
}
public class Derived : C
{
    // warning CS8765: Type of parameter 'value' doesn't match overridden member because of nullability attributes.
    internal override bool TryGetValueCore<TKey, TValue>(TKey key, string valueProvider, [MaybeNull] [NotNullWhen(true)] out TValue value)
        {
        throw null!;
        }
}

sharplab

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions