From 0c00e7e733cc74ddaba38f571334cc8c39794886 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Thu, 11 Jul 2024 11:10:11 +0200 Subject: [PATCH 1/3] Handle span conversions in expression trees --- .../DiagnosticsPass_ExpressionTrees.cs | 2 - .../LocalRewriter/LocalRewriter_Conversion.cs | 2 +- .../CSharp/Test/Emit3/FirstClassSpanTests.cs | 416 ++++++++++++++++++ 3 files changed, 417 insertions(+), 3 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Lowering/DiagnosticsPass_ExpressionTrees.cs b/src/Compilers/CSharp/Portable/Lowering/DiagnosticsPass_ExpressionTrees.cs index ca544bb53940a..1f401b2ef6eff 100644 --- a/src/Compilers/CSharp/Portable/Lowering/DiagnosticsPass_ExpressionTrees.cs +++ b/src/Compilers/CSharp/Portable/Lowering/DiagnosticsPass_ExpressionTrees.cs @@ -811,8 +811,6 @@ public override BoundNode VisitConversion(BoundConversion node) } break; - // PROTOTYPE: ImplicitSpan - default: if (_inExpressionLambda && node.Conversion.Method is MethodSymbol method && (method.IsAbstract || method.IsVirtual) && method.IsStatic) diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Conversion.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Conversion.cs index 90bd13ffa13c1..b276230485812 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Conversion.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Conversion.cs @@ -629,7 +629,7 @@ private BoundExpression MakeConversionNodeCore( rewrittenOperand = _factory.Convert(method.ParameterTypesWithAnnotations[0].Type, rewrittenOperand); - if (_compilation.IsReadOnlySpanType(spanType)) + if (!_inExpressionLambda && _compilation.IsReadOnlySpanType(spanType)) { return new BoundReadOnlySpanFromArray(syntax, rewrittenOperand, method, spanType) { WasCompilerGenerated = true }; } diff --git a/src/Compilers/CSharp/Test/Emit3/FirstClassSpanTests.cs b/src/Compilers/CSharp/Test/Emit3/FirstClassSpanTests.cs index a8f84ee322fbf..00cc772b3f151 100644 --- a/src/Compilers/CSharp/Test/Emit3/FirstClassSpanTests.cs +++ b/src/Compilers/CSharp/Test/Emit3/FirstClassSpanTests.cs @@ -1826,6 +1826,196 @@ unsafe static class C Diagnostic(ErrorCode.ERR_MethFuncPtrMismatch, "&C.M").WithArguments("C.M(System.Span)", "delegate*").WithLocation(5, 9)); } + [Theory, CombinatorialData] + public void Conversion_Array_Span_Implicit_ExpressionTree_01( + [CombinatorialValues("Span", "ReadOnlySpan")] string type) + { + var source = $$""" + using System; + using System.Linq.Expressions; + + C.R(a => C.M(a)); + + static class C + { + public static void R(Expression> e) => e.Compile()(new string[] { "a" }); + public static void M({{type}} x) => Console.Write(x.Length + " " + x[0]); + } + """; + + var expectedOutput = "1 a"; + + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular12); + var verifier = CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); + verifier.VerifyIL("", $$""" + { + // Code size 108 (0x6c) + .maxstack 9 + .locals init (System.Linq.Expressions.ParameterExpression V_0) + IL_0000: ldtoken "string[]" + IL_0005: call "System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)" + IL_000a: ldstr "a" + IL_000f: call "System.Linq.Expressions.ParameterExpression System.Linq.Expressions.Expression.Parameter(System.Type, string)" + IL_0014: stloc.0 + IL_0015: ldnull + IL_0016: ldtoken "void C.M(System.{{type}})" + IL_001b: call "System.Reflection.MethodBase System.Reflection.MethodBase.GetMethodFromHandle(System.RuntimeMethodHandle)" + IL_0020: castclass "System.Reflection.MethodInfo" + IL_0025: ldc.i4.1 + IL_0026: newarr "System.Linq.Expressions.Expression" + IL_002b: dup + IL_002c: ldc.i4.0 + IL_002d: ldloc.0 + IL_002e: ldtoken "System.{{type}}" + IL_0033: call "System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)" + IL_0038: ldtoken "System.{{type}} System.{{type}}.op_Implicit(string[])" + IL_003d: ldtoken "System.{{type}}" + IL_0042: call "System.Reflection.MethodBase System.Reflection.MethodBase.GetMethodFromHandle(System.RuntimeMethodHandle, System.RuntimeTypeHandle)" + IL_0047: castclass "System.Reflection.MethodInfo" + IL_004c: call "System.Linq.Expressions.UnaryExpression System.Linq.Expressions.Expression.Convert(System.Linq.Expressions.Expression, System.Type, System.Reflection.MethodInfo)" + IL_0051: stelem.ref + IL_0052: call "System.Linq.Expressions.MethodCallExpression System.Linq.Expressions.Expression.Call(System.Linq.Expressions.Expression, System.Reflection.MethodInfo, params System.Linq.Expressions.Expression[])" + IL_0057: ldc.i4.1 + IL_0058: newarr "System.Linq.Expressions.ParameterExpression" + IL_005d: dup + IL_005e: ldc.i4.0 + IL_005f: ldloc.0 + IL_0060: stelem.ref + IL_0061: call "System.Linq.Expressions.Expression> System.Linq.Expressions.Expression.Lambda>(System.Linq.Expressions.Expression, params System.Linq.Expressions.ParameterExpression[])" + IL_0066: call "void C.R(System.Linq.Expressions.Expression>)" + IL_006b: ret + } + """); + + var expectedIl = $$""" + { + // Code size 108 (0x6c) + .maxstack 11 + .locals init (System.Linq.Expressions.ParameterExpression V_0) + IL_0000: ldtoken "string[]" + IL_0005: call "System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)" + IL_000a: ldstr "a" + IL_000f: call "System.Linq.Expressions.ParameterExpression System.Linq.Expressions.Expression.Parameter(System.Type, string)" + IL_0014: stloc.0 + IL_0015: ldnull + IL_0016: ldtoken "void C.M(System.{{type}})" + IL_001b: call "System.Reflection.MethodBase System.Reflection.MethodBase.GetMethodFromHandle(System.RuntimeMethodHandle)" + IL_0020: castclass "System.Reflection.MethodInfo" + IL_0025: ldc.i4.1 + IL_0026: newarr "System.Linq.Expressions.Expression" + IL_002b: dup + IL_002c: ldc.i4.0 + IL_002d: ldnull + IL_002e: ldtoken "System.{{type}} System.{{type}}.op_Implicit(string[])" + IL_0033: ldtoken "System.{{type}}" + IL_0038: call "System.Reflection.MethodBase System.Reflection.MethodBase.GetMethodFromHandle(System.RuntimeMethodHandle, System.RuntimeTypeHandle)" + IL_003d: castclass "System.Reflection.MethodInfo" + IL_0042: ldc.i4.1 + IL_0043: newarr "System.Linq.Expressions.Expression" + IL_0048: dup + IL_0049: ldc.i4.0 + IL_004a: ldloc.0 + IL_004b: stelem.ref + IL_004c: call "System.Linq.Expressions.MethodCallExpression System.Linq.Expressions.Expression.Call(System.Linq.Expressions.Expression, System.Reflection.MethodInfo, params System.Linq.Expressions.Expression[])" + IL_0051: stelem.ref + IL_0052: call "System.Linq.Expressions.MethodCallExpression System.Linq.Expressions.Expression.Call(System.Linq.Expressions.Expression, System.Reflection.MethodInfo, params System.Linq.Expressions.Expression[])" + IL_0057: ldc.i4.1 + IL_0058: newarr "System.Linq.Expressions.ParameterExpression" + IL_005d: dup + IL_005e: ldc.i4.0 + IL_005f: ldloc.0 + IL_0060: stelem.ref + IL_0061: call "System.Linq.Expressions.Expression> System.Linq.Expressions.Expression.Lambda>(System.Linq.Expressions.Expression, params System.Linq.Expressions.ParameterExpression[])" + IL_0066: call "void C.R(System.Linq.Expressions.Expression>)" + IL_006b: ret + } + """; + + comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.RegularNext); + verifier = CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); + verifier.VerifyIL("", expectedIl); + + comp = CreateCompilationWithSpan(source); + verifier = CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); + verifier.VerifyIL("", expectedIl); + } + + [Theory, CombinatorialData] + public void Conversion_Array_Span_Implicit_ExpressionTree_02( + [CombinatorialLangVersions] LanguageVersion langVersion, + [CombinatorialValues("Span", "ReadOnlySpan")] string type) + { + var source = $$""" + using System; + using System.Linq.Expressions; + + C.R(() => C.M(null)); + + static class C + { + public static void R(Expression e) { } + public static void M({{type}} x) { } + } + """; + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); + var verifier = CompileAndVerify(comp).VerifyDiagnostics(); + verifier.VerifyIL("", $$""" + { + // Code size 97 (0x61) + .maxstack 9 + IL_0000: ldnull + IL_0001: ldtoken "void C.M(System.{{type}})" + IL_0006: call "System.Reflection.MethodBase System.Reflection.MethodBase.GetMethodFromHandle(System.RuntimeMethodHandle)" + IL_000b: castclass "System.Reflection.MethodInfo" + IL_0010: ldc.i4.1 + IL_0011: newarr "System.Linq.Expressions.Expression" + IL_0016: dup + IL_0017: ldc.i4.0 + IL_0018: ldnull + IL_0019: ldtoken "string[]" + IL_001e: call "System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)" + IL_0023: call "System.Linq.Expressions.ConstantExpression System.Linq.Expressions.Expression.Constant(object, System.Type)" + IL_0028: ldtoken "System.{{type}}" + IL_002d: call "System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)" + IL_0032: ldtoken "System.{{type}} System.{{type}}.op_Implicit(string[])" + IL_0037: ldtoken "System.{{type}}" + IL_003c: call "System.Reflection.MethodBase System.Reflection.MethodBase.GetMethodFromHandle(System.RuntimeMethodHandle, System.RuntimeTypeHandle)" + IL_0041: castclass "System.Reflection.MethodInfo" + IL_0046: call "System.Linq.Expressions.UnaryExpression System.Linq.Expressions.Expression.Convert(System.Linq.Expressions.Expression, System.Type, System.Reflection.MethodInfo)" + IL_004b: stelem.ref + IL_004c: call "System.Linq.Expressions.MethodCallExpression System.Linq.Expressions.Expression.Call(System.Linq.Expressions.Expression, System.Reflection.MethodInfo, params System.Linq.Expressions.Expression[])" + IL_0051: call "System.Linq.Expressions.ParameterExpression[] System.Array.Empty()" + IL_0056: call "System.Linq.Expressions.Expression System.Linq.Expressions.Expression.Lambda(System.Linq.Expressions.Expression, params System.Linq.Expressions.ParameterExpression[])" + IL_005b: call "void C.R(System.Linq.Expressions.Expression)" + IL_0060: ret + } + """); + } + + [Theory, CombinatorialData] + public void Conversion_Array_Span_Implicit_ExpressionTree_03( + [CombinatorialLangVersions] LanguageVersion langVersion, + [CombinatorialValues("Span", "ReadOnlySpan")] string type) + { + var source = $$""" + using System; + using System.Linq.Expressions; + + C.R(() => C.M(default)); + + static class C + { + public static void R(Expression e) => e.Compile()(); + public static void M({{type}} x) => Console.Write(x.Length); + } + """; + + CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)).VerifyDiagnostics( + // (4,15): error CS8640: Expression tree cannot contain value of ref struct or restricted type 'Span'. + // C.R(() => C.M(default)); + Diagnostic(ErrorCode.ERR_ExpressionTreeCantContainRefStruct, "default").WithArguments(type).WithLocation(4, 15)); + } + [Theory, CombinatorialData] public void Conversion_Array_ReadOnlySpan_Covariant( [CombinatorialLangVersions] LanguageVersion langVersion, @@ -3352,6 +3542,136 @@ static class C CompileAndVerify(comp, expectedOutput: "11").VerifyDiagnostics(); } + [Theory, MemberData(nameof(LangVersions))] + public void OverloadResolution_ReadOnlySpanVsArray_06(LanguageVersion langVersion) + { + var source = """ + using System; + + C.M(default(object[])); + + static class C + { + public static void M(object[] x) => Console.Write(1); + public static void M(ReadOnlySpan x) => Console.Write(2); + } + """; + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); + CompileAndVerify(comp, expectedOutput: "1").VerifyDiagnostics(); + } + + [Theory, MemberData(nameof(LangVersions))] + public void OverloadResolution_ReadOnlySpanVsArray_ExpressionTree_01(LanguageVersion langVersion) + { + var source = """ + using System; + using System.Linq.Expressions; + + var a = new string[] { "a" }; + C.R(() => C.M(a)); + + static class C + { + public static void R(Expression e) => e.Compile()(); + public static void M(string[] x) => Console.Write(" s" + x[0]); + public static void M(ReadOnlySpan x) => Console.Write(" o" + x[0]); + } + """; + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); + CompileAndVerify(comp, expectedOutput: "sa").VerifyDiagnostics(); + } + + [Fact] + public void OverloadResolution_ReadOnlySpanVsArray_ExpressionTree_02() + { + var source = """ + using System; + using System.Linq.Expressions; + + var a = new string[] { "a" }; + C.R(() => C.M(a)); + + static class C + { + public static void R(Expression e) => e.Compile()(); + public static void M(object[] x) => Console.Write(" a" + x[0]); + public static void M(ReadOnlySpan x) => Console.Write(" r" + x[0]); + } + """; + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular12); + CompileAndVerify(comp, expectedOutput: "aa").VerifyDiagnostics(); + + var expectedOutput = "ra"; + + comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.RegularNext); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); + + comp = CreateCompilationWithSpan(source); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); + } + + [Theory, MemberData(nameof(LangVersions))] + public void OverloadResolution_ReadOnlySpanVsArray_ExpressionTree_03(LanguageVersion langVersion) + { + var source = """ + using System; + using System.Linq.Expressions; + + var a = new object[] { "a" }; + C.R(() => C.M(a)); + + static class C + { + public static void R(Expression e) => e.Compile()(); + public static void M(object[] x) => Console.Write(" a" + x[0]); + public static void M(ReadOnlySpan x) => Console.Write(" r" + x[0]); + } + """; + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); + CompileAndVerify(comp, expectedOutput: "aa").VerifyDiagnostics(); + } + + [Theory, MemberData(nameof(LangVersions))] + public void OverloadResolution_ReadOnlySpanVsArray_ExpressionTree_04(LanguageVersion langVersion) + { + var source = """ + using System; + using System.Linq.Expressions; + + C.R(() => C.M(null)); + C.R(() => C.M(default)); + + static class C + { + public static void R(Expression e) => e.Compile()(); + public static void M(object[] x) => Console.Write(" a" + (x?[0] ?? "null")); + public static void M(ReadOnlySpan x) => Console.Write(" r" + x.Length); + } + """; + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); + CompileAndVerify(comp, expectedOutput: "anull anull").VerifyDiagnostics(); + } + + [Theory, MemberData(nameof(LangVersions))] + public void OverloadResolution_ReadOnlySpanVsArray_ExpressionTree_05(LanguageVersion langVersion) + { + var source = """ + using System; + using System.Linq.Expressions; + + C.R(() => C.M(default(object[]))); + + static class C + { + public static void R(Expression e) => e.Compile()(); + public static void M(object[] x) => Console.Write(1); + public static void M(ReadOnlySpan x) => Console.Write(2); + } + """; + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); + CompileAndVerify(comp, expectedOutput: "1").VerifyDiagnostics(); + } + [Fact] public void OverloadResolution_ReadOnlySpanVsArray_Params_01() { @@ -3575,6 +3895,102 @@ static class C CompileAndVerify(comp, expectedOutput: "11").VerifyDiagnostics(); } + [Theory, MemberData(nameof(LangVersions))] + public void OverloadResolution_SpanVsArray_ExtensionMethodReceiver_01(LanguageVersion langVersion) + { + var source = """ + using System; + + var a = new string[] { "a" }; + a.M(); + + static class C + { + public static void M(this string[] x) => Console.Write(" a" + x[0]); + public static void M(this Span x) => Console.Write(" s" + x[0]); + } + """; + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); + CompileAndVerify(comp, expectedOutput: "aa").VerifyDiagnostics(); + } + + [Fact] + public void OverloadResolution_SpanVsArray_ExtensionMethodReceiver_02() + { + var source = """ + using System; + + var a = new string[] { "a" }; + a.M(); + + static class C + { + public static void M(this object[] x) => Console.Write(" a" + x[0]); + public static void M(this Span x) => Console.Write(" s" + x[0]); + } + """; + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular12); + CompileAndVerify(comp, expectedOutput: "aa").VerifyDiagnostics(); + + var expectedOutput = "sa"; + + comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.RegularNext); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); + + comp = CreateCompilationWithSpan(source); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); + } + + [Theory, MemberData(nameof(LangVersions))] + public void OverloadResolution_SpanVsArray_ExtensionMethodReceiver_ExpressionTree_01(LanguageVersion langVersion) + { + var source = """ + using System; + using System.Linq.Expressions; + + var a = new string[] { "a" }; + C.R(() => a.M()); + + static class C + { + public static void R(Expression e) => e.Compile()(); + public static void M(this string[] x) => Console.Write(" a" + x[0]); + public static void M(this Span x) => Console.Write(" s" + x[0]); + } + """; + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); + CompileAndVerify(comp, expectedOutput: "aa").VerifyDiagnostics(); + } + + [Fact] + public void OverloadResolution_SpanVsArray_ExtensionMethodReceiver_ExpressionTree_02() + { + var source = """ + using System; + using System.Linq.Expressions; + + var a = new string[] { "a" }; + C.R(() => a.M()); + + static class C + { + public static void R(Expression e) => e.Compile()(); + public static void M(this object[] x) => Console.Write(" a" + x[0]); + public static void M(this Span x) => Console.Write(" s" + x[0]); + } + """; + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular12); + CompileAndVerify(comp, expectedOutput: "aa").VerifyDiagnostics(); + + var expectedOutput = "sa"; + + comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.RegularNext); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); + + comp = CreateCompilationWithSpan(source); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); + } + [Theory, MemberData(nameof(LangVersions))] public void OverloadResolution_SpanVsReadOnlySpan_01(LanguageVersion langVersion) { From e30fa15c42b9b68ced92fbf3a945161227cb9325 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Thu, 11 Jul 2024 19:23:33 +0200 Subject: [PATCH 2/3] Improve test readability --- src/Compilers/CSharp/Test/Emit3/FirstClassSpanTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit3/FirstClassSpanTests.cs b/src/Compilers/CSharp/Test/Emit3/FirstClassSpanTests.cs index 00cc772b3f151..af0c275687e69 100644 --- a/src/Compilers/CSharp/Test/Emit3/FirstClassSpanTests.cs +++ b/src/Compilers/CSharp/Test/Emit3/FirstClassSpanTests.cs @@ -3644,12 +3644,12 @@ public void OverloadResolution_ReadOnlySpanVsArray_ExpressionTree_04(LanguageVer static class C { public static void R(Expression e) => e.Compile()(); - public static void M(object[] x) => Console.Write(" a" + (x?[0] ?? "null")); - public static void M(ReadOnlySpan x) => Console.Write(" r" + x.Length); + public static void M(object[] x) => Console.Write(" 1" + (x?[0] ?? "null")); + public static void M(ReadOnlySpan x) => Console.Write(" 2" + x.Length); } """; var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); - CompileAndVerify(comp, expectedOutput: "anull anull").VerifyDiagnostics(); + CompileAndVerify(comp, expectedOutput: "1null 1null").VerifyDiagnostics(); } [Theory, MemberData(nameof(LangVersions))] From 3c067b36bd571e00530e5e298c06f8139cf7609c Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Mon, 15 Jul 2024 10:01:40 +0200 Subject: [PATCH 3/3] Consolidate tests --- .../CSharp/Test/Emit3/FirstClassSpanTests.cs | 42 ++----------------- 1 file changed, 3 insertions(+), 39 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit3/FirstClassSpanTests.cs b/src/Compilers/CSharp/Test/Emit3/FirstClassSpanTests.cs index af0c275687e69..8d9b2f34bc062 100644 --- a/src/Compilers/CSharp/Test/Emit3/FirstClassSpanTests.cs +++ b/src/Compilers/CSharp/Test/Emit3/FirstClassSpanTests.cs @@ -3531,23 +3531,6 @@ public void OverloadResolution_ReadOnlySpanVsArray_05(LanguageVersion langVersio C.M(null); C.M(default); - - static class C - { - public static void M(object[] x) => Console.Write(1); - public static void M(ReadOnlySpan x) => Console.Write(2); - } - """; - var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); - CompileAndVerify(comp, expectedOutput: "11").VerifyDiagnostics(); - } - - [Theory, MemberData(nameof(LangVersions))] - public void OverloadResolution_ReadOnlySpanVsArray_06(LanguageVersion langVersion) - { - var source = """ - using System; - C.M(default(object[])); static class C @@ -3557,7 +3540,7 @@ static class C } """; var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); - CompileAndVerify(comp, expectedOutput: "1").VerifyDiagnostics(); + CompileAndVerify(comp, expectedOutput: "111").VerifyDiagnostics(); } [Theory, MemberData(nameof(LangVersions))] @@ -3640,6 +3623,7 @@ public void OverloadResolution_ReadOnlySpanVsArray_ExpressionTree_04(LanguageVer C.R(() => C.M(null)); C.R(() => C.M(default)); + C.R(() => C.M(default(object[]))); static class C { @@ -3649,27 +3633,7 @@ static class C } """; var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); - CompileAndVerify(comp, expectedOutput: "1null 1null").VerifyDiagnostics(); - } - - [Theory, MemberData(nameof(LangVersions))] - public void OverloadResolution_ReadOnlySpanVsArray_ExpressionTree_05(LanguageVersion langVersion) - { - var source = """ - using System; - using System.Linq.Expressions; - - C.R(() => C.M(default(object[]))); - - static class C - { - public static void R(Expression e) => e.Compile()(); - public static void M(object[] x) => Console.Write(1); - public static void M(ReadOnlySpan x) => Console.Write(2); - } - """; - var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); - CompileAndVerify(comp, expectedOutput: "1").VerifyDiagnostics(); + CompileAndVerify(comp, expectedOutput: "1null 1null 1null").VerifyDiagnostics(); } [Fact]