diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index a736a55585cfa..73e7395ac0267 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -146808,5 +146808,32 @@ void M(T initial, System.Func selector) var comp = CreateCompilation(src); comp.VerifyDiagnostics(); } + + [Theory, WorkItem(52925, "https://github.com/dotnet/roslyn/issues/52925")] + [InlineData("")] + [InlineData(" where T : notnull")] + [InlineData(" where T : class")] + [InlineData(" where T : class?")] + public void VarDeclarationWithGenericType_RefValue(string constraint) + { + var src = $@" +#nullable enable + +class C {constraint} +{{ + ref T Passthrough(ref T value) + {{ + ref var value2 = ref value; + return ref value2; + }} +}} +"; + var comp = CreateCompilation(src); + comp.VerifyDiagnostics( + // (9,20): warning CS8619: Nullability of reference types in value of type 'T?' doesn't match target type 'T'. + // return ref value2; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "value2").WithArguments("T?", "T").WithLocation(9, 20) + ); + } } } diff --git a/src/Dependencies/Collections/SegmentedDictionary`2.cs b/src/Dependencies/Collections/SegmentedDictionary`2.cs index 271585109af14..123f0e73cc5a8 100644 --- a/src/Dependencies/Collections/SegmentedDictionary`2.cs +++ b/src/Dependencies/Collections/SegmentedDictionary`2.cs @@ -442,7 +442,7 @@ private ref TValue FindValue(TKey key) ConcurrentOperation: ThrowHelper.ThrowInvalidOperationException_ConcurrentOperationsNotSupported(); ReturnFound: - ref var value = ref entry._value; + ref TValue value = ref entry._value; Return: return ref value; ReturnNotFound: