Skip to content

Commit 07e4433

Browse files
authored
Add errors and warnings related to overload resolution (dotnet#42563)
* Add new updates for Orpa Add the new compiler errors and warnings related to Overload Resolution Priority. * Move and consolidate content * warnings * Consolidate descriptions of overload issues Consolidate the description for the reason for different errors and the steps to fix those errors. * Add ambiguity errors types * warnings * Final edits * Fix related errors * typo
1 parent f8c356e commit 07e4433

22 files changed

+246
-998
lines changed

.openpublishing.redirection.csharp.json

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@
307307
"source_path_from_root": "/docs/csharp/language-reference/builtin-types/nint-nuint.md",
308308
"redirect_url": "/dotnet/csharp/language-reference/builtin-types/integral-numeric-types#native-sized-integers"
309309
},
310+
{
311+
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs0034.md",
312+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
313+
},
310314
{
311315
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs0178.md",
312316
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
@@ -367,10 +371,23 @@
367371
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs0854.md",
368372
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
369373
},
374+
{
375+
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1019.md",
376+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
377+
},
378+
{
379+
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1063.md",
380+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
381+
382+
},
370383
{
371384
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1067.md",
372385
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-types"
373386
},
387+
{
388+
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1501.md",
389+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
390+
},
374391
{
375392
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1704.md",
376393
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/assembly-references"
@@ -1469,10 +1486,22 @@
14691486
"source_path_from_root": "/docs/csharp/misc/cs0022.md",
14701487
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
14711488
},
1489+
{
1490+
"source_path_from_root": "/docs/csharp/misc/cs0035.md",
1491+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
1492+
},
14721493
{
14731494
"source_path_from_root": "/docs/csharp/misc/cs0105.md",
14741495
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/using-directive-errors"
14751496
},
1497+
{
1498+
"source_path_from_root": "/docs/csharp/misc/cs0111.md",
1499+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
1500+
},
1501+
{
1502+
"source_path_from_root": "/docs/csharp/misc/cs0121.md",
1503+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
1504+
},
14761505
{
14771506
"source_path_from_root": "/docs/csharp/misc/cs0138.md",
14781507
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/using-directive-errors"
@@ -1565,6 +1594,10 @@
15651594
"source_path_from_root": "/docs/csharp/misc/cs0440.md",
15661595
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/using-directive-errors"
15671596
},
1597+
{
1598+
"source_path_from_root": "/docs/csharp/misc/cs0457.md",
1599+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
1600+
},
15681601
{
15691602
"source_path_from_root": "/docs/csharp/misc/cs0466.md",
15701603
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/params-arrays"
@@ -1641,6 +1674,10 @@
16411674
"source_path_from_root": "/docs/csharp/misc/cs0655.md",
16421675
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch"
16431676
},
1677+
{
1678+
"source_path_from_root": "/docs/csharp/misc/cs0663.md",
1679+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
1680+
},
16441681
{
16451682
"source_path_from_root": "/docs/csharp/misc/cs0674.md",
16461683
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/params-arrays"
@@ -1749,10 +1786,18 @@
17491786
"source_path_from_root": "/docs/csharp/misc/cs1016.md",
17501787
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch"
17511788
},
1789+
{
1790+
"source_path_from_root": "/docs/csharp/misc/cs1020.md",
1791+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
1792+
},
17521793
{
17531794
"source_path_from_root": "/docs/csharp/misc/cs1104.md",
17541795
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/params-arrays"
17551796
},
1797+
{
1798+
"source_path_from_root": "/docs/csharp/misc/cs1007.md",
1799+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
1800+
},
17561801
{
17571802
"source_path_from_root": "/docs/csharp/misc/cs1510.md",
17581803
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/ref-modifiers-errors"
@@ -1825,6 +1870,14 @@
18251870
"source_path_from_root": "/docs/csharp/misc/cs1632.md",
18261871
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/lambda-expression-errors#syntax-limitations-in-lambda-expressions"
18271872
},
1873+
{
1874+
"source_path_from_root": "/docs/csharp/misc/cs1534.md",
1875+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
1876+
},
1877+
{
1878+
"source_path_from_root": "/docs/csharp/misc/cs1535.md",
1879+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
1880+
},
18281881
{
18291882
"source_path_from_root": "/docs/csharp/misc/cs1637.md",
18301883
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/iterator-yield"
@@ -1873,6 +1926,14 @@
18731926
"source_path_from_root": "/docs/csharp/misc/cs1925.md",
18741927
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
18751928
},
1929+
{
1930+
"source_path_from_root": "/docs/csharp/misc/cs1928.md",
1931+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
1932+
},
1933+
{
1934+
"source_path_from_root": "/docs/csharp/misc/cs1929.md",
1935+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
1936+
},
18761937
{
18771938
"source_path_from_root": "/docs/csharp/misc/cs1939.md",
18781939
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/ref-modifiers-errors"
@@ -1885,6 +1946,10 @@
18851946
"source_path_from_root": "/docs/csharp/misc/cs1945.md",
18861947
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
18871948
},
1949+
{
1950+
"source_path_from_root": "/docs/csharp/misc/cs1950.md",
1951+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
1952+
},
18881953
{
18891954
"source_path_from_root": "/docs/csharp/misc/cs1951.md",
18901955
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
@@ -1901,6 +1966,10 @@
19011966
"source_path_from_root": "/docs/csharp/misc/cs1954.md",
19021967
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
19031968
},
1969+
{
1970+
"source_path_from_root": "/docs/csharp/misc/cs3006.md",
1971+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
1972+
},
19041973
{
19051974
"source_path_from_root": "/docs/csharp/misc/cs3016.md",
19061975
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"

docs/csharp/language-reference/compiler-messages/array-declaration-errors.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ f1_keywords:
1515
- "CS0820"
1616
- "CS0826"
1717
- "CS0846"
18+
- "CS1062"
19+
- "CS1063"
20+
- "CS1064"
1821
- "CS1552"
1922
- "CS1586"
2023
- "CS1920"
2124
- "CS1921"
2225
- "CS1925"
26+
- "CS1950"
2327
- "CS1954"
2428
- "CS3007"
2529
- "CS3016"
@@ -49,9 +53,13 @@ helpviewer_keywords:
4953
- "CS0846"
5054
- "CS1552"
5155
- "CS1586"
56+
- "CS1062"
57+
- "CS1063"
58+
- "CS1064"
5259
- "CS1920"
5360
- "CS1921"
5461
- "CS1925"
62+
- "CS1950"
5563
- "CS1954"
5664
- "CS3007"
5765
- "CS3016"
@@ -86,11 +94,13 @@ That's by design. The text closely matches the text of the compiler error / warn
8694
- [**CS0820**](#invalid-element-type): *Cannot assign array initializer to an implicitly typed local*
8795
- [**CS0826**](#invalid-element-type): *No best type found for implicitly typed array.*
8896
- [**CS0846**](#invalid-array-initializer): *A nested array initializer is expected*
97+
- [**CS1063**](#invalid-collection-initializer): *The best overloaded Add method for the collection initializer element is obsolete.*
8998
- [**CS1552**](#invalid-array-rank): *Array type specifier, `[]`, must appear before parameter name*
9099
- [**CS1586**](#invalid-array-length): *Array creation must have array size or array initializer*
91100
- [**CS1920**](#invalid-collection-initializer): *Element initializer cannot be empty.*
92101
- [**CS1921**](#invalid-collection-initializer): *The best overloaded method match has wrong signature for the initializer element. The initializable `Add` must be an accessible instance method.*
93102
- [**CS1925**](#invalid-array-initializer): *Cannot initialize object of type 'type' with a collection initializer.*
103+
- [**CS1950**](#invalid-collection-initializer): *The best overloaded Add method for the collection initializer has some invalid arguments.*
94104
- [**CS1954**](#invalid-collection-initializer): *The best overloaded method match for the collection initializer element cannot be used. Collection initializer '`Add`' methods cannot have `ref` or `out` parameters.*
95105
- [**CS9174**](#invalid-collection-initializer): *Cannot initialize type with a collection literal because the type is not constructible.*
96106
- [**CS9176**](#invalid-collection-initializer): *There is no target type for the collection literal.*
@@ -103,6 +113,8 @@ That's by design. The text closely matches the text of the compiler error / warn
103113

104114
In addition, the following warnings are covered in this article:
105115

116+
- [**CS1062**](#invalid-collection-initializer): *The best overloaded Add method for the collection initializer element is obsolete.*
117+
- [**CS1064**](#invalid-collection-initializer): *The best overloaded Add method for the collection initializer element is obsolete.*
106118
- [**CS3007**](#common-language-specification-warnings): *Overloaded method 'method' differing only by unnamed array types is not CLS-compliant*
107119
- [**CS3016**](#common-language-specification-warnings): *Arrays as attribute arguments is not CLS-compliant*
108120
- [**CS0251**](#invalid-array-element-access): *Indexing an array with a negative index (array indices always start at zero)*
@@ -120,8 +132,10 @@ You can learn more about arrays, collection initializers and collection expressi
120132
The following errors indicate that the code generated by the compiler for a collection initializer is invalid:
121133

122134
- **CS0747**: *Invalid initializer member declarator.*
135+
- **CS1063**: *The best overloaded Add method for the collection initializer element is obsolete.*
123136
- **CS1920**: *Element initializer cannot be empty.*
124137
- **CS1921**: *The best overloaded method match has wrong signature for the initializer element. The initializable `Add` must be an accessible instance method.*
138+
- **CS1950**: *The best overloaded Add method for the collection initializer has some invalid arguments.*
125139
- **CS1954**: *The best overloaded method match for the collection initializer element cannot be used. Collection initializer '`Add`' methods cannot have `ref` or `out` parameters.*
126140
- **CS9174**: *Cannot initialize type with a collection literal because the type is not constructible.*
127141
- **CS9176**: *There is no target type for the collection literal.*
@@ -130,13 +144,16 @@ The following errors indicate that the code generated by the compiler for a coll
130144

131145
The compiler might also generate the following warning:
132146

147+
- **CS1062**: *The best overloaded Add method for the collection initializer element is obsolete.*
148+
- **CS1064**: *The best overloaded Add method for the collection initializer element is obsolete.*
133149
- **CS9208**: *Collection expression may incur unexpected heap allocations. Consider explicitly creating an array, then converting to the final type to make the allocation explicit.*
134150
- **CS9209**: *Collection expression may incur unexpected heap allocations due to use of '`..`' spreads. Consider explicitly creating an array, then converting to the final type to make the allocation explicit.*
135151

136152
The errors all indicate that the code generated by the compiler for a collection initializer is invalid. Check the following:
137153

138154
- A collection initializer contains a sequence of elements. You can't mix setting properties on the collection instance with adding elements in the same initializer.
139155
- A collection initializer that includes braces (`{` and `}`) can't be empty.
156+
- The class must implement IEnumerable and have a public `Add` method.
140157
- A conforming `Add` method must be accessible and take one parameter that is the same type as the collection elements. The parameter can't include the `ref` or `out` modifier.
141158
- Overload resolution must pick one `Add` method as a better match. There can't be multiple matching methods that are equally good.
142159
- Collection expressions can initialize explicitly typed variables of a collection type. If the variable isn't a collection or array type, or is implicitly typed (using `var`), a collection initializer can't be used.

docs/csharp/language-reference/compiler-messages/cs0034.md

Lines changed: 0 additions & 107 deletions
This file was deleted.

0 commit comments

Comments
 (0)