Skip to content

Commit 7674a00

Browse files
committed
Tweaks
1 parent 2c211ce commit 7674a00

File tree

4 files changed

+192
-92
lines changed

4 files changed

+192
-92
lines changed

src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ internal BoundExpression MakeInvocationExpression(
137137
}
138138

139139
BoundExpression result = BindInvocationExpression(
140-
node, node, methodName, boundExpression, analyzedArguments, diagnostics, queryClause,
141-
ignoreNormalFormIfHasValidParamsParameter: ignoreNormalFormIfHasValidParamsParameter,
142-
disallowExpandedNonArrayParams: disallowExpandedNonArrayParams, acceptOnlyMethods: !allowFieldsAndProperties);
140+
node, node, methodName, boundExpression, analyzedArguments, diagnostics, acceptOnlyMethods: !allowFieldsAndProperties,
141+
queryClause, ignoreNormalFormIfHasValidParamsParameter: ignoreNormalFormIfHasValidParamsParameter,
142+
disallowExpandedNonArrayParams: disallowExpandedNonArrayParams);
143143

144144
// Query operator can't be called dynamically.
145145
if (queryClause != null && result.Kind == BoundKind.DynamicInvocation)
@@ -324,10 +324,10 @@ private BoundExpression BindInvocationExpression(
324324
BoundExpression boundExpression,
325325
AnalyzedArguments analyzedArguments,
326326
BindingDiagnosticBag diagnostics,
327+
bool acceptOnlyMethods,
327328
CSharpSyntaxNode queryClause = null,
328329
bool ignoreNormalFormIfHasValidParamsParameter = false,
329-
bool disallowExpandedNonArrayParams = false,
330-
bool acceptOnlyMethods = false)
330+
bool disallowExpandedNonArrayParams = false)
331331
{
332332
//
333333
// !!! ATTENTION !!!

src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ObjectOrCollectionInitializerExpression.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,8 @@ private BoundExpression MakeObjectInitializerMemberAccess(
702702
_compilation.Conversions.HasImplicitConversionToOrImplementsVarianceCompatibleInterface(rewrittenReceiver.Type, memberSymbol.ContainingType, ref discardedUseSiteInfo, out _));
703703
// It is possible there are use site diagnostics from the above, but none that we need report as we aren't generating code for the conversion
704704
#endif
705+
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : handle creating a conversion on receiver
706+
// TODO2
705707

706708
switch (memberSymbol.Kind)
707709
{

src/Compilers/CSharp/Test/Emit3/Semantics/ExtensionTests.cs

Lines changed: 115 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15835,13 +15835,31 @@ public class MyCollection : IEnumerable<int>
1583515835
IEnumerator IEnumerable.GetEnumerator() => throw null;
1583615836
}
1583715837
""";
15838-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how delegate-returning properties play into pattern-based constructs
1583915838
var comp = CreateCompilation(source);
1584015839
comp.VerifyEmitDiagnostics(
1584115840
// (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?)
1584215841
// MyCollection c = [42];
1584315842
Diagnostic(ErrorCode.ERR_NoSuchMemberOrExtension, "[42]").WithArguments("MyCollection", "Add").WithLocation(4, 18)
1584415843
);
15844+
15845+
source = """
15846+
using System.Collections;
15847+
using System.Collections.Generic;
15848+
15849+
MyCollection c = [42];
15850+
15851+
public class MyCollection : IEnumerable<int>
15852+
{
15853+
IEnumerator<int> IEnumerable<int>.GetEnumerator() => throw null;
15854+
IEnumerator IEnumerable.GetEnumerator() => throw null;
15855+
public System.Action<int> Add => (int i) => { };
15856+
}
15857+
""";
15858+
comp = CreateCompilation(source);
15859+
comp.VerifyEmitDiagnostics(
15860+
// (4,18): error CS0118: 'Add' is a property but is used like a method
15861+
// MyCollection c = [42];
15862+
Diagnostic(ErrorCode.ERR_BadSKknown, "[42]").WithArguments("Add", "property", "method").WithLocation(4, 18));
1584515863
}
1584615864

1584715865
[Fact]
@@ -15867,12 +15885,30 @@ public class MyCollection : IEnumerable<int>
1586715885
IEnumerator IEnumerable.GetEnumerator() => throw null;
1586815886
}
1586915887
""";
15870-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how dynamic-returning properties play into pattern-based constructs
1587115888
var comp = CreateCompilation(source);
1587215889
comp.VerifyEmitDiagnostics(
1587315890
// (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?)
1587415891
// MyCollection c = [42];
1587515892
Diagnostic(ErrorCode.ERR_NoSuchMemberOrExtension, "[42]").WithArguments("MyCollection", "Add").WithLocation(4, 18));
15893+
15894+
source = """
15895+
using System.Collections;
15896+
using System.Collections.Generic;
15897+
15898+
MyCollection c = [42];
15899+
15900+
public class MyCollection : IEnumerable<int>
15901+
{
15902+
IEnumerator<int> IEnumerable<int>.GetEnumerator() => throw null;
15903+
IEnumerator IEnumerable.GetEnumerator() => throw null;
15904+
public dynamic Add => throw null;
15905+
}
15906+
""";
15907+
comp = CreateCompilation(source);
15908+
comp.VerifyEmitDiagnostics(
15909+
// (4,18): error CS0118: 'Add' is a property but is used like a method
15910+
// MyCollection c = [42];
15911+
Diagnostic(ErrorCode.ERR_BadSKknown, "[42]").WithArguments("Add", "property", "method").WithLocation(4, 18));
1587615912
}
1587715913

1587815914
[Fact]
@@ -20183,7 +20219,6 @@ static class E
2018320219
}
2018420220
}
2018520221
""";
20186-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how delegate-returning properties play into pattern-based constructs
2018720222
var comp = CreateCompilation(src);
2018820223
comp.VerifyEmitDiagnostics(
2018920224
// (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
2019420229
var model = comp.GetSemanticModel(tree);
2019520230
var loop = tree.GetRoot().DescendantNodes().OfType<ForEachStatementSyntax>().Single();
2019620231
Assert.Null(model.GetForEachStatementInfo(loop).GetEnumeratorMethod);
20232+
20233+
src = """
20234+
using System.Collections;
20235+
20236+
foreach (var x in new C()) { }
20237+
20238+
class C
20239+
{
20240+
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));
2019720251
}
2019820252

2019920253
[Fact]
20200-
public void ExtensionMemberLookup_PatternBased_ForEach_DynamicTypeProperty()
20254+
public void ExtensionMemberLookup_PatternBased_ForEach_GetEnumerator_DynamicTypeProperty()
2020120255
{
2020220256
var src = """
2020320257
using System.Collections;
@@ -20214,7 +20268,6 @@ static class E
2021420268
}
2021520269
}
2021620270
""";
20217-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how dynamic-returning properties play into pattern-based constructs
2021820271
var comp = CreateCompilation(src);
2021920272
comp.VerifyEmitDiagnostics(
2022020273
// (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
2022520278
var model = comp.GetSemanticModel(tree);
2022620279
var loop = tree.GetRoot().DescendantNodes().OfType<ForEachStatementSyntax>().Single();
2022720280
Assert.Null(model.GetForEachStatementInfo(loop).GetEnumeratorMethod);
20281+
20282+
src = """
20283+
foreach (var x in new C()) { }
20284+
20285+
class C
20286+
{
20287+
public dynamic GetEnumerator => throw null;
20288+
}
20289+
""";
20290+
comp = CreateCompilation(src);
20291+
comp.VerifyEmitDiagnostics(
20292+
// (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));
2022820298
}
2022920299

2023020300
[Fact]
20231-
public void ExtensionMemberLookup_PatternBased_ForEach_Generic()
20301+
public void ExtensionMemberLookup_PatternBased_ForEach_GetEnumerator_Generic()
2023220302
{
2023320303
var src = """
2023420304
using System.Collections.Generic;
@@ -20259,7 +20329,7 @@ public IEnumerator<T> GetEnumerator()
2025920329
}
2026020330

2026120331
[Fact]
20262-
public void ExtensionMemberLookup_PatternBased_AwaitForEach()
20332+
public void ExtensionMemberLookup_PatternBased_AwaitForEach_GetAsyncEnumerator()
2026320333
{
2026420334
var src = """
2026520335
using System.Collections.Generic;
@@ -20428,7 +20498,6 @@ static class E
2042820498
}
2042920499
""";
2043020500
var comp = CreateCompilation(src);
20431-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how delegate-returning properties play into pattern-based constructs
2043220501
comp.VerifyDiagnostics(
2043320502
// (1,6): error CS8130: Cannot infer the type of implicitly-typed deconstruction variable 'x1'.
2043420503
// var (x1, y1) = new C1();
@@ -20787,6 +20856,20 @@ static class E
2078720856
// (1,1): error CS1674: 'S1': type used in a using statement must implement 'System.IDisposable'.
2078820857
// using var x1 = new S1();
2078920858
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));
2079020873
}
2079120874

2079220875
[Fact]
@@ -20894,7 +20977,6 @@ static class E
2089420977
}
2089520978
";
2089620979
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
2089820980
comp.VerifyEmitDiagnostics(
2089920981
// (6,25): error CS8385: The given expression cannot be used in a fixed statement
2090020982
// fixed (int* p = new Fixable1())
@@ -20932,7 +21014,30 @@ static class E
2093221014
}
2093321015
";
2093421016
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;
21036+
}
21037+
21038+
delegate ref int MyDelegate();
21039+
";
21040+
comp = CreateCompilation(text, options: TestOptions.UnsafeReleaseExe);
2093621041
comp.VerifyEmitDiagnostics(
2093721042
// (6,25): error CS8385: The given expression cannot be used in a fixed statement
2093821043
// fixed (int* p = new Fixable1())
@@ -21203,7 +21308,6 @@ static class E
2120321308
}
2120421309
";
2120521310

21206-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how delegate-returning properties play into pattern-based constructs
2120721311
var comp = CreateCompilation(text);
2120821312
comp.VerifyEmitDiagnostics(
2120921313
// (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
2126721371
}
2126821372
";
2126921373

21270-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how dynamic-returning properties play into pattern-based constructs
2127121374
var comp = CreateCompilation(text);
2127221375
comp.VerifyEmitDiagnostics(
2127321376
// (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
2140121504
}
2140221505
}
2140321506
";
21404-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how delegate-returning properties play into pattern-based constructs
2140521507
var comp = CreateCompilation(text);
2140621508
comp.VerifyEmitDiagnostics(
2140721509
// (5,9): error CS0117: 'D' does not contain a definition for 'GetResult'
@@ -22532,7 +22634,6 @@ public class MyCollection : IEnumerable<int>
2253222634
IEnumerator IEnumerable.GetEnumerator() => throw null;
2253322635
}
2253422636
""";
22535-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how delegate-returning properties play into pattern-based constructs
2253622637
var comp = CreateCompilation(source);
2253722638
comp.VerifyEmitDiagnostics(
2253822639
// (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>
2258222683
IEnumerator IEnumerable.GetEnumerator() => throw null;
2258322684
}
2258422685
""";
22585-
// Tracked by https://github.com/dotnet/roslyn/issues/76130 : revisit how dynamic-returning properties play into pattern-based constructs
2258622686
var comp = CreateCompilation(source);
2258722687
comp.VerifyEmitDiagnostics(
2258822688
// (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

Comments
 (0)