-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
good first issuehelp-wantedA change up for grabs for contributions from the communityA change up for grabs for contributions from the community
Description
I was reviewing some code and noticed a hidden bug: null could be returned, but there was no compiler warning. This is because TryLookupByType lacks the [NotNullWhen(true)] annotation, which is used, for example, in IPAddress.TryParse.
It would be helpful if SchemaRepository.TryLookupByType were annotated for nullability, similar to my workaround below:
#nullable enable
public static bool TryLookupByTypeSafe(this SchemaRepository schemaRepository,
Type type, [NotNullWhen(true)] out OpenApiSchemaReference? referenceSchema)
{
bool result = schemaRepository.TryLookupByType(type,
out OpenApiSchemaReference? obliviousReferenceSchema);
referenceSchema = result ? obliviousReferenceSchema : null;
return result;
}
#nullable restoreAnd then the hidden bug becomes a compiler warning:

Frulfump and wajahati
Metadata
Metadata
Assignees
Labels
good first issuehelp-wantedA change up for grabs for contributions from the communityA change up for grabs for contributions from the community