You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ObjectOrCollectionInitializerExpression.cs
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how delegate-returning properties play into pattern-based constructs
15839
15838
var comp = CreateCompilation(source);
15840
15839
comp.VerifyEmitDiagnostics(
15841
15840
// (4,18): error CS1061: 'MyCollection' does not contain a definition for 'Add' and no accessible extension method 'Add' accepting a first argument of type 'MyCollection' could be found (are you missing a using directive or an assembly reference?)
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how dynamic-returning properties play into pattern-based constructs
15871
15888
var comp = CreateCompilation(source);
15872
15889
comp.VerifyEmitDiagnostics(
15873
15890
// (4,18): error CS1061: 'MyCollection' does not contain a definition for 'Add' and no accessible extension method 'Add' accepting a first argument of type 'MyCollection' could be found (are you missing a using directive or an assembly reference?)
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how delegate-returning properties play into pattern-based constructs
20187
20222
var comp = CreateCompilation(src);
20188
20223
comp.VerifyEmitDiagnostics(
20189
20224
// (3,19): error CS1579: foreach statement cannot operate on variables of type 'C' because 'C' does not contain a public instance or extension definition for 'GetEnumerator'
@@ -20194,10 +20229,29 @@ static class E
20194
20229
var model = comp.GetSemanticModel(tree);
20195
20230
var loop = tree.GetRoot().DescendantNodes().OfType<ForEachStatementSyntax>().Single();
public System.Func<IEnumerator> GetEnumerator => throw null;
20241
+
}
20242
+
""";
20243
+
comp = CreateCompilation(src);
20244
+
comp.VerifyEmitDiagnostics(
20245
+
// (3,19): warning CS0280: 'C' does not implement the 'collection' pattern. 'C.GetEnumerator' has the wrong signature.
20246
+
// foreach (var x in new C()) { }
20247
+
Diagnostic(ErrorCode.WRN_PatternBadSignature, "new C()").WithArguments("C", "collection", "C.GetEnumerator").WithLocation(3, 19),
20248
+
// (3,19): error CS1579: foreach statement cannot operate on variables of type 'C' because 'C' does not contain a public instance or extension definition for 'GetEnumerator'
20249
+
// foreach (var x in new C()) { }
20250
+
Diagnostic(ErrorCode.ERR_ForEachMissingMember, "new C()").WithArguments("C", "GetEnumerator").WithLocation(3, 19));
20197
20251
}
20198
20252
20199
20253
[Fact]
20200
-
public void ExtensionMemberLookup_PatternBased_ForEach_DynamicTypeProperty()
20254
+
public void ExtensionMemberLookup_PatternBased_ForEach_GetEnumerator_DynamicTypeProperty()
20201
20255
{
20202
20256
var src = """
20203
20257
using System.Collections;
@@ -20214,7 +20268,6 @@ static class E
20214
20268
}
20215
20269
}
20216
20270
""";
20217
-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how dynamic-returning properties play into pattern-based constructs
20218
20271
var comp = CreateCompilation(src);
20219
20272
comp.VerifyEmitDiagnostics(
20220
20273
// (3,19): error CS1579: foreach statement cannot operate on variables of type 'C' because 'C' does not contain a public instance or extension definition for 'GetEnumerator'
@@ -20225,10 +20278,27 @@ static class E
20225
20278
var model = comp.GetSemanticModel(tree);
20226
20279
var loop = tree.GetRoot().DescendantNodes().OfType<ForEachStatementSyntax>().Single();
// (1,19): warning CS0280: 'C' does not implement the 'collection' pattern. 'C.GetEnumerator' has the wrong signature.
20293
+
// foreach (var x in new C()) { }
20294
+
Diagnostic(ErrorCode.WRN_PatternBadSignature, "new C()").WithArguments("C", "collection", "C.GetEnumerator").WithLocation(1, 19),
20295
+
// (1,19): error CS1579: foreach statement cannot operate on variables of type 'C' because 'C' does not contain a public instance or extension definition for 'GetEnumerator'
20296
+
// foreach (var x in new C()) { }
20297
+
Diagnostic(ErrorCode.ERR_ForEachMissingMember, "new C()").WithArguments("C", "GetEnumerator").WithLocation(1, 19));
20228
20298
}
20229
20299
20230
20300
[Fact]
20231
-
public void ExtensionMemberLookup_PatternBased_ForEach_Generic()
20301
+
public void ExtensionMemberLookup_PatternBased_ForEach_GetEnumerator_Generic()
20232
20302
{
20233
20303
var src = """
20234
20304
using System.Collections.Generic;
@@ -20259,7 +20329,7 @@ public IEnumerator<T> GetEnumerator()
20259
20329
}
20260
20330
20261
20331
[Fact]
20262
-
public void ExtensionMemberLookup_PatternBased_AwaitForEach()
20332
+
public void ExtensionMemberLookup_PatternBased_AwaitForEach_GetAsyncEnumerator()
20263
20333
{
20264
20334
var src = """
20265
20335
using System.Collections.Generic;
@@ -20428,7 +20498,6 @@ static class E
20428
20498
}
20429
20499
""";
20430
20500
var comp = CreateCompilation(src);
20431
-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how delegate-returning properties play into pattern-based constructs
20432
20501
comp.VerifyDiagnostics(
20433
20502
// (1,6): error CS8130: Cannot infer the type of implicitly-typed deconstruction variable 'x1'.
20434
20503
// var (x1, y1) = new C1();
@@ -20787,6 +20856,20 @@ static class E
20787
20856
// (1,1): error CS1674: 'S1': type used in a using statement must implement 'System.IDisposable'.
20788
20857
// using var x1 = new S1();
20789
20858
Diagnostic(ErrorCode.ERR_NoConvToIDisp, "using var x1 = new S1();").WithArguments("S1").WithLocation(1, 1));
20859
+
20860
+
src = """
20861
+
using var x1 = new S1();
20862
+
20863
+
ref struct S1
20864
+
{
20865
+
public System.Action Dispose => throw null;
20866
+
}
20867
+
""";
20868
+
comp = CreateCompilation(src);
20869
+
comp.VerifyDiagnostics(
20870
+
// (1,1): error CS1674: 'S1': type used in a using statement must implement 'System.IDisposable'.
20871
+
// using var x1 = new S1();
20872
+
Diagnostic(ErrorCode.ERR_NoConvToIDisp, "using var x1 = new S1();").WithArguments("S1").WithLocation(1, 1));
20790
20873
}
20791
20874
20792
20875
[Fact]
@@ -20894,7 +20977,6 @@ static class E
20894
20977
}
20895
20978
";
20896
20979
var comp = CreateCompilation(text, options: TestOptions.UnsafeReleaseExe);
20897
-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how delegate-returning properties play into pattern-based constructs
20898
20980
comp.VerifyEmitDiagnostics(
20899
20981
// (6,25): error CS8385: The given expression cannot be used in a fixed statement
20900
20982
// fixed (int* p = new Fixable1())
@@ -20932,7 +21014,30 @@ static class E
20932
21014
}
20933
21015
";
20934
21016
var comp = CreateCompilation(text, options: TestOptions.UnsafeReleaseExe);
20935
-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how dynamic-returning properties play into pattern-based constructs
21017
+
comp.VerifyEmitDiagnostics(
21018
+
// (6,25): error CS8385: The given expression cannot be used in a fixed statement
21019
+
// fixed (int* p = new Fixable1())
21020
+
Diagnostic(ErrorCode.ERR_ExprCannotBeFixed, "new Fixable1()").WithLocation(6, 25));
21021
+
21022
+
text = @"
21023
+
unsafe class C
21024
+
{
21025
+
public static void Main()
21026
+
{
21027
+
fixed (int* p = new Fixable1())
21028
+
{
21029
+
}
21030
+
}
21031
+
}
21032
+
21033
+
class Fixable1
21034
+
{
21035
+
public dynamic GetPinnableReference => throw null;
// (6,25): error CS8385: The given expression cannot be used in a fixed statement
20938
21043
// fixed (int* p = new Fixable1())
@@ -21203,7 +21308,6 @@ static class E
21203
21308
}
21204
21309
";
21205
21310
21206
-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how delegate-returning properties play into pattern-based constructs
21207
21311
var comp = CreateCompilation(text);
21208
21312
comp.VerifyEmitDiagnostics(
21209
21313
// (5,9): error CS1061: 'C' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'C' could be found (are you missing a using directive or an assembly reference?)
@@ -21267,7 +21371,6 @@ static class E
21267
21371
}
21268
21372
";
21269
21373
21270
-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how dynamic-returning properties play into pattern-based constructs
21271
21374
var comp = CreateCompilation(text);
21272
21375
comp.VerifyEmitDiagnostics(
21273
21376
// (5,9): error CS1061: 'C' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'C' could be found (are you missing a using directive or an assembly reference?)
@@ -21401,7 +21504,6 @@ static class E
21401
21504
}
21402
21505
}
21403
21506
";
21404
-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how delegate-returning properties play into pattern-based constructs
21405
21507
var comp = CreateCompilation(text);
21406
21508
comp.VerifyEmitDiagnostics(
21407
21509
// (5,9): error CS0117: 'D' does not contain a definition for 'GetResult'
@@ -22532,7 +22634,6 @@ public class MyCollection : IEnumerable<int>
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how delegate-returning properties play into pattern-based constructs
22536
22637
var comp = CreateCompilation(source);
22537
22638
comp.VerifyEmitDiagnostics(
22538
22639
// (4,39): error CS1061: 'MyCollection' does not contain a definition for 'Add' and no accessible extension method 'Add' accepting a first argument of type 'MyCollection' could be found (are you missing a using directive or an assembly reference?)
@@ -22582,7 +22683,6 @@ public class MyCollection : IEnumerable<int>
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how dynamic-returning properties play into pattern-based constructs
22586
22686
var comp = CreateCompilation(source);
22587
22687
comp.VerifyEmitDiagnostics(
22588
22688
// (4,39): error CS1061: 'MyCollection' does not contain a definition for 'Add' and no accessible extension method 'Add' accepting a first argument of type 'MyCollection' could be found (are you missing a using directive or an assembly reference?)
0 commit comments