@@ -1401,12 +1434,14 @@ public Conversion ClassifyImplicitExtensionMethodThisArgConversion(BoundExpressi
if((object)sourceType!=null)
{
Debug.Assert(!IncludeNullability);// PROTOTYPE(NullableReferenceTypes): Should fail in StaticNullChecking_FlowAnalysis.Conversions_TupleLiteralExtensionThis.
CSharpCompilation c = CreateStandardCompilation(@"
class C
...
...
@@ -3992,7 +3992,7 @@ class CL1
}
[Fact]
public void PassingParameters_2()
public void PassingParameters_02()
{
CSharpCompilation c = CreateStandardCompilation(@"
class C
...
...
@@ -4025,7 +4025,7 @@ class CL0
}
[Fact]
public void PassingParameters_3()
public void PassingParameters_03()
{
CSharpCompilation c = CreateStandardCompilation(@"
class C
...
...
@@ -4295,12 +4295,12 @@ class CL0<T>
", parseOptions: TestOptions.Regular8);
c.VerifyDiagnostics(
// (12,16): warning CS8620: Nullability of reference types in argument of type 'CL0<string?>' doesn't match target type 'CL0<string>' for parameter 'x' in 'void C.M1(ref CL0<string> x)'.
// (12,16): warning CS8620: Nullability of reference types in argument of type 'CL0<string?>' doesn't match target type 'CL0<string>' for parameter 'x' in 'void C.M1(ref CL0<string> x)'.
CSharpCompilation c = CreateStandardCompilation(@"
...
...
@@ -8396,6 +8424,49 @@ class CL1<T>
);
}
[Fact]
public void UnboundLambda_01()
{
var source =
@"class C
{
static void F()
{
var y = x => x;
}
}";
var comp = CreateStandardCompilation(source, parseOptions: TestOptions.Regular8);
comp.VerifyDiagnostics(
// (5,13): error CS0815: Cannot assign lambda expression to an implicitly-typed variable
// var y = x => x;
Diagnostic(ErrorCode.ERR_ImplicitlyTypedVariableAssignedBadValue, "y = x => x").WithArguments("lambda expression").WithLocation(5, 13));
}
[Fact]
public void UnboundLambda_02()
{
var source =
@"class C
{
static void F(object? x)
{
var z = y => y ?? x.ToString();
}
}";
// PROTOTYPE(NullableReferenceTypes): Should not report HDN_ExpressionIsProbablyNeverNull for `y`.
var comp = CreateStandardCompilation(source, parseOptions: TestOptions.Regular8);
comp.VerifyDiagnostics(
// (5,13): error CS0815: Cannot assign lambda expression to an implicitly-typed variable
// var z = y => y ?? x.ToString();
Diagnostic(ErrorCode.ERR_ImplicitlyTypedVariableAssignedBadValue, "z = y => y ?? x.ToString()").WithArguments("lambda expression").WithLocation(5, 13),
// (5,22): hidden CS8607: Expression is probably never null.
var comp = CreateStandardCompilation(source, parseOptions: TestOptions.Regular8);
comp.VerifyDiagnostics();
}
[Fact]
public void BinaryOperator_15()
{
var source =
@"struct S
{
public static S operator+(S a, S b) => a;
static void F(S x, S? y)
{
S? s;
s = x + x;
s = x + y;
s = y + x;
s = y + y;
}
}";
var comp = CreateStandardCompilation(source, parseOptions: TestOptions.Regular8);
comp.VerifyDiagnostics();
}
[Fact]
public void BinaryOperator_16()
{
var source =
@"struct S
{
public static bool operator<(S a, S b) => true;
public static bool operator<=(S a, S b) => true;
public static bool operator>(S a, S b) => true;
public static bool operator>=(S a, S b) => true;
public static bool operator==(S a, S b) => true;
public static bool operator!=(S a, S b) => true;
public override bool Equals(object other) => true;
public override int GetHashCode() => 0;
static void F(S x, S? y)
{
if (x < y) { }
if (x <= y) { }
if (x > y) { }
if (x >= y) { }
if (x == y) { }
if (x != y) { }
if (y < x) { }
if (y <= x) { }
if (y > x) { }
if (y >= x) { }
if (y == x) { }
if (y != x) { }
}
}";
var comp = CreateStandardCompilation(source, parseOptions: TestOptions.Regular8);
comp.VerifyDiagnostics();
}
[Fact]
public void MethodGroupConversion_01()
{
...
...
@@ -10326,9 +10504,9 @@ class CL0<T>
", parseOptions: TestOptions.Regular8);
c.VerifyDiagnostics(
// (12,35): warning CS8621: Nullability of reference types in return type of 'string C.M1<string>()' doesn't match the target delegate 'Func<string?>'.
// (12,35): warning CS8621: Nullability of reference types in return type of 'string C.M1<string>()' doesn't match the target delegate 'Func<string?>'.
// (17,34): warning CS8621: Nullability of reference types in return type of 'string? C.M1<string?>()' doesn't match the target delegate 'Func<string>'.
// (7,9): warning CS8619: Nullability of reference types in value of type 'I<object?>' doesn't match target type 'I<object>'.
// (7,9): warning CS8620: Nullability of reference types in argument of type 'C<object?>' doesn't match target type 'I<object>' for parameter 'o' in 'void E.F1(I<object> o)'.
// (9,9): warning CS8620: Nullability of reference types in argument of type 'C<object>' doesn't match target type 'I<object?>' for parameter 'o' in 'void E.F2(I<object?> o)'.
// PROTOTYPE(NullableReferenceTypes): Should report WRN_NullabilityMismatch*.
[Fact(Skip = "TODO")]
[Fact]
public void SuppressNullableWarning_Ref()
{
var source =
...
...
@@ -16189,12 +16386,6 @@ static void Main()
parseOptions: TestOptions.Regular8,
options: TestOptions.ReleaseExe);
comp.VerifyDiagnostics(
// (10,15): warning CS8620: Nullability of reference types in argument of type 'string' doesn't match target type 'string' for parameter 's' in 'void C.F(ref string s, ref string? t)'.
// (10,22): warning CS8620: Nullability of reference types in argument of type 'string' doesn't match target type 'string' for parameter 't' in 'void C.F(ref string s, ref string? t)'.
// PROTOTYPE(NullableReferenceTypes): Should report WRN_NullabilityMismatch*.
[Fact(Skip = "TODO")]
[Fact]
public void SuppressNullableWarning_Out()
{
var source =
...
...
@@ -16228,12 +16418,6 @@ static void Main()
parseOptions: TestOptions.Regular8,
options: TestOptions.ReleaseExe);
comp.VerifyDiagnostics(
// (12,15): warning CS8620: Nullability of reference types in argument of type 'string' doesn't match target type 'string' for parameter 's' in 'void C.F(out string s, out string? t)'.
// (12,22): warning CS8620: Nullability of reference types in argument of type 'string' doesn't match target type 'string' for parameter 't' in 'void C.F(out string s, out string? t)'.
// (6,21): warning CS8619: Nullability of reference types in value of type '(I<object?>, I<object>)?' doesn't match target type '(I<object>, I<object?>)?'.
// (10,21): warning CS8619: Nullability of reference types in value of type '(I<object?>, I<object>)' doesn't match target type '(I<object>, I<object?>)'.