Skip to content
Permalink
Browse files

Merge pull request #39711 from dotnet/merges/release/dev16.4-to-master

Merge release/dev16.4 to master
  • Loading branch information...
msftbot committed Nov 7, 2019
2 parents 5882a87 + e8a800c commit 4f38fdac37fabe1414f089de9759f7e1a7d90c03
@@ -72,12 +72,9 @@ the compiler didn't look for the name in base interfaces of the interface. Looku
hierarchy or through usings. We now look in base interfaces and find types declared within them, if any match the name. The type
could be different than the one that compiler used to find.

10. https://github.com/dotnet/csharplang/blob/master/meetings/2019/LDM-2019-09-11.md In C# `8.0` no warning is reported at the production or dereference of a maybe-null value for a type that is a type parameter that cannot be annotated with `?`, except if the value was produced by `default(T)`.
In Visual Studio version 16.4, the nullable analysis will be more stringent for such values. Whenever such a value is produced, as warning will be reported. For instance, when invoking a method that returns a `[MaybeNull]T`.

11. https://github.com/dotnet/roslyn/issues/38427 C# `7.0` incorrectly allowed duplicate type constraints with tuple name differences. In *Visual Studio 2019 version 16.4* we will make it an error.
10. https://github.com/dotnet/roslyn/issues/38427 C# `7.0` incorrectly allowed duplicate type constraints with tuple name differences. In *Visual Studio 2019 version 16.4* this is an error.
```C#
class C<T> where T : I<(int a, int b)>, I<(int c, int d)> { } // error
```

12. Previously, the language version was not checked for `this ref` and `this in` orderings of parameter modifiers. In *Visual Studio 2019 version 16.4* these orderings produce an error with langversion below 7.2. See https://github.com/dotnet/roslyn/issues/38486
11. Previously, the language version was not checked for `this ref` and `this in` orderings of parameter modifiers. In *Visual Studio 2019 version 16.4* these orderings produce an error with langversion below 7.2. See https://github.com/dotnet/roslyn/issues/38486
@@ -1523,13 +1523,6 @@ private static bool RequiresSafetyWarningWhenNullIntroduced(TypeSymbol type)
!type.IsNullableTypeOrTypeParameter();
}

private static bool RequiresSafetyWarningWhenNullIntroduced(TypeSymbol type, FlowAnalysisAnnotations annotations)
{
return
(annotations & FlowAnalysisAnnotations.MaybeNull) != 0 &&
type.IsTypeParameterDisallowingAnnotation();
}

public override BoundNode VisitLocal(BoundLocal node)
{
var local = node.LocalSymbol;
@@ -3187,10 +3180,7 @@ private void ReinferMethodAndVisitArguments(BoundCall node, TypeWithState receiv
/// </summary>
private void ReportMaybeNullFromTypeParameterValueIfNeeded(BoundExpression expr, TypeWithState typeWithState, FlowAnalysisAnnotations annotations)
{
if (!expr.IsSuppressed && !typeWithState.IsNotNull && RequiresSafetyWarningWhenNullIntroduced(typeWithState.Type, annotations))
{
ReportDiagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, expr.Syntax, GetTypeAsDiagnosticArgument(expr.Type));
}
// Not implemented. See https://github.com/dotnet/roslyn/issues/38638 for an alternative.
}

private void LearnFromEqualsMethod(MethodSymbol method, BoundCall node, TypeWithState receiverType, ImmutableArray<VisitArgumentResult> results)
}";
var comp = CreateNullableCompilation(new[] { MaybeNullWhenAttributeDefinition, source });
comp.VerifyDiagnostics(
// (11,24): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// _ = F1(t1, out var s2) // 0
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "var s2").WithArguments("T").WithLocation(11, 24),
// (12,15): warning CS8602: Dereference of a possibly null reference.
// ? s2.ToString() // 1
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "s2").WithLocation(12, 15),
}";
var expected = new[]
{
// (7,9): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// new COpen<T>().P1.ToString(); // 0, 1
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "new COpen<T>().P1").WithArguments("T").WithLocation(7, 9),
// (7,9): warning CS8602: Dereference of a possibly null reference.
// new COpen<T>().P1.ToString(); // 0, 1
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "new COpen<T>().P1").WithLocation(7, 9),
// (11,9): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// xOpen.P1.ToString(); // 2, 3
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "xOpen.P1").WithArguments("T").WithLocation(11, 9),
// (11,9): warning CS8602: Dereference of a possibly null reference.
// xOpen.P1.ToString(); // 2, 3
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "xOpen.P1").WithLocation(11, 9),
// (14,13): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// if (xOpen2.P1 is object) // 4
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "xOpen2.P1").WithArguments("T").WithLocation(14, 13),
// (21,9): warning CS8602: Dereference of a possibly null reference.
// new COpen<T>().P1.ToString(); // 5
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "new COpen<T>().P1").WithLocation(21, 9),
}";
var expected = new[]
{
// (6,9): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// new COpen<T>().P1.ToString(); // 0, 1
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "new COpen<T>().P1").WithArguments("T").WithLocation(6, 9),
// (6,9): warning CS8602: Dereference of a possibly null reference.
// new COpen<T>().P1.ToString(); // 0, 1
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "new COpen<T>().P1").WithLocation(6, 9),
}";
var comp = CreateNullableCompilation(new[] { source, MaybeNullAttributeDefinition });
comp.VerifyDiagnostics(
// (9,9): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// c.P.ToString(); // 1, 2
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "c.P").WithArguments("T").WithLocation(9, 9),
// (9,9): warning CS8602: Dereference of a possibly null reference.
// c.P.ToString(); // 1, 2
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "c.P").WithLocation(9, 9),
// (12,9): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// c.P.ToString(); // 3, 4
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "c.P").WithArguments("T").WithLocation(12, 9),
// (12,9): warning CS8602: Dereference of a possibly null reference.
// c.P.ToString(); // 3, 4
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "c.P").WithLocation(12, 9)
}";
var expected = new[]
{
// (8,9): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// new COpen<T>().f1.ToString(); // 0, 1
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "new COpen<T>().f1").WithArguments("T").WithLocation(8, 9),
// (8,9): warning CS8602: Dereference of a possibly null reference.
// new COpen<T>().f1.ToString(); // 0, 1
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "new COpen<T>().f1").WithLocation(8, 9),
// (12,9): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// xOpen.f1.ToString(); // 2, 3
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "xOpen.f1").WithArguments("T").WithLocation(12, 9),
// (12,9): warning CS8602: Dereference of a possibly null reference.
// xOpen.f1.ToString(); // 2, 3
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "xOpen.f1").WithLocation(12, 9),
// (15,9): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// xOpen2.f1.ToString(); // 4, 5
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "xOpen2.f1").WithArguments("T").WithLocation(15, 9),
// (15,9): warning CS8602: Dereference of a possibly null reference.
// xOpen2.f1.ToString(); // 4, 5
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "xOpen2.f1").WithLocation(15, 9),
// (19,13): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// if (xOpen3.f1 is object) // 6
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "xOpen3.f1").WithArguments("T").WithLocation(19, 13),
// (26,9): warning CS8602: Dereference of a possibly null reference.
// new COpen<T>().f1.ToString(); // 7
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "new COpen<T>().f1").WithLocation(26, 9),
}";
var comp = CreateCompilation(new[] { MaybeNullAttributeDefinition, source }, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics(
// (11,9): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// F1(t1).ToString(); // 0, 1
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "F1(t1)").WithArguments("T").WithLocation(11, 9),
// (11,9): warning CS8602: Dereference of a possibly null reference.
// F1(t1).ToString(); // 0, 1
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "F1(t1)").WithLocation(11, 9),
}";
var comp = CreateCompilation(new[] { MaybeNullAttributeDefinition, source }, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics(
// (11,9): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// F1<T>(t1).ToString(); // 1
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "F1<T>(t1)").WithArguments("T").WithLocation(11, 9),
// (11,9): warning CS8602: Dereference of a possibly null reference.
// F1<T>(t1).ToString(); // 1
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "F1<T>(t1)").WithLocation(11, 9),
}";
var comp = CreateCompilation(new[] { MaybeNullAttributeDefinition, NotNullAttributeDefinition, source }, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics(
// (11,9): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// F1<T>(t1).ToString(); // 0, 1
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "F1<T>(t1)").WithArguments("T").WithLocation(11, 9),
// (11,9): warning CS8602: Dereference of a possibly null reference.
// F1<T>(t1).ToString(); // 0, 1
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "F1<T>(t1)").WithLocation(11, 9),
}";
var comp = CreateCompilation(new[] { MaybeNullAttributeDefinition, source }, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics(
// (12,9): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// C<T>.F().ToString(); // 0, 1
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "C<T>.F()").WithArguments("T").WithLocation(12, 9),
// (12,9): warning CS8602: Dereference of a possibly null reference.
// C<T>.F().ToString(); // 0, 1
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "C<T>.F()").WithLocation(12, 9),
}";
var comp = CreateNullableCompilation(new[] { MaybeNullAttributeDefinition, source });
comp.VerifyDiagnostics(
// (11,20): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// F1(t1, out var s2); // 0
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "var s2").WithArguments("T").WithLocation(11, 20),
// (12,9): warning CS8602: Dereference of a possibly null reference.
// s2.ToString(); // 1
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "s2").WithLocation(12, 9),
}";
var comp = CreateNullableCompilation(new[] { MaybeNullAttributeDefinition, source });
comp.VerifyDiagnostics(
// (11,23): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// F1<T>(t1, out var s1); // 0
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "var s1").WithArguments("T").WithLocation(11, 23),
// (12,9): warning CS8602: Dereference of a possibly null reference.
// s1.ToString(); // 1
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "s1").WithLocation(12, 9),
}";
var comp = CreateNullableCompilation(new[] { MaybeNullAttributeDefinition, source });
comp.VerifyDiagnostics(
// (12,20): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// C<T>.F(out var o1); // 0
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "var o1").WithArguments("T").WithLocation(12, 20),
// (13,9): warning CS8602: Dereference of a possibly null reference.
// o1.ToString(); // 1
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "o1").WithLocation(13, 9),
}";
var comp = CreateNullableCompilation(new[] { MaybeNullAttributeDefinition, source });
comp.VerifyDiagnostics(
// (12,20): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// F1(t1, ref s2); // 0
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "s2").WithArguments("T").WithLocation(12, 20),
// (13,9): warning CS8602: Dereference of a possibly null reference.
// s2.ToString(); // 1
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "s2").WithLocation(13, 9),
);
}

[Fact]
public void MaybeNull_MemberReference()
{
var source =
@"#nullable enable
using System.Diagnostics.CodeAnalysis;
class C<T>
{
[MaybeNull] T F = default!;
[MaybeNull] T P => default!;
void M1()
{
_ = F;
}
static void M2(C<T> c)
{
_ = c.P;
}
}";
var comp = CreateCompilation(new[] { MaybeNullAttributeDefinition, source });
comp.VerifyDiagnostics();
}

[Fact]
public void MaybeNull_MethodCall()
{
var source =
@"#nullable enable
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
static class E
{
[return: MaybeNull] internal static T FirstOrDefault<T>(this IEnumerable<T> e) => throw null!;
internal static bool TryGet<K, V>(this Dictionary<K, V> d, K key, [MaybeNullWhen(false)] out V value) => throw null!;
}
class Program
{
[return: MaybeNull] static T M1<T>(IEnumerable<T> e)
{
e.FirstOrDefault();
_ = e.FirstOrDefault();
return e.FirstOrDefault();
}
static void M2<K, V>(Dictionary<K, V> d, K key)
{
d.TryGet(key, out var value);
}
}";
var comp = CreateCompilation(new[] { MaybeNullAttributeDefinition, MaybeNullWhenAttributeDefinition, source });
comp.VerifyDiagnostics();
}

[Fact]
public void NotNull_ReturnValue_01()
{
}";
var comp = CreateCompilation(new[] { MaybeNullAttributeDefinition, NotNullAttributeDefinition, source }, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics(
// (10,14): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// var (x1, y1) = p; // 0
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "x1").WithArguments("T").WithLocation(10, 14),
// (11,9): warning CS8602: Dereference of a possibly null reference.
// x1.ToString(); // 1
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "x1").WithLocation(11, 9),
// (17,9): warning CS8602: Dereference of a possibly null reference.
// x2.ToString(); // 2
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "x2").WithLocation(17, 9),
// (22,14): warning CS8717: A member returning a [MaybeNull] value introduces a null value when 'T' is a non-nullable reference type.
// var (x3, y3) = p; // 3
Diagnostic(ErrorCode.WRN_ExpressionMayIntroduceNullT, "x3").WithArguments("T").WithLocation(22, 14),
// (23,9): warning CS8602: Dereference of a possibly null reference.
// x3.ToString(); // 4
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "x3").WithLocation(23, 9),
@@ -397,6 +397,16 @@ public void TryParseDisplayName()
TestParseDisplayName("goo, Culture=neutral, Version=1.0.0.0, Culture=en-US", null);
}

[Fact]
[WorkItem(39647, "https://github.com/dotnet/roslyn/issues/39647")]
public void AssemblyIdentity_EmptyName()
{
var identity = new AssemblyIdentity(noThrow: true, name: "");
var name = identity.GetDisplayName();
Assert.Equal(", Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", name);
Assert.False(AssemblyIdentity.TryParseDisplayName(name, out _));
}

[ConditionalFact(typeof(WindowsDesktopOnly), Reason = ConditionalSkipReason.TestExecutionNeedsFusion)]
public void TryParseDisplayName_Version()
{

0 comments on commit 4f38fda

Please sign in to comment.
You can’t perform that action at this time.