Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add errors and warnings related to overload resolution #42563

Merged
merged 9 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .openpublishing.redirection.csharp.json
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@
"source_path_from_root": "/docs/csharp/language-reference/builtin-types/nint-nuint.md",
"redirect_url": "/dotnet/csharp/language-reference/builtin-types/integral-numeric-types#native-sized-integers"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs0034.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs0178.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
Expand Down Expand Up @@ -367,10 +371,23 @@
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs0854.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1019.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1063.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"

},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1067.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-types"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1501.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1704.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/assembly-references"
Expand Down Expand Up @@ -1469,10 +1486,22 @@
"source_path_from_root": "/docs/csharp/misc/cs0022.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0035.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0105.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/using-directive-errors"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0111.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0121.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0138.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/using-directive-errors"
Expand Down Expand Up @@ -1565,6 +1594,10 @@
"source_path_from_root": "/docs/csharp/misc/cs0440.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/using-directive-errors"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0457.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0466.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/params-arrays"
Expand Down Expand Up @@ -1641,6 +1674,10 @@
"source_path_from_root": "/docs/csharp/misc/cs0655.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0663.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0674.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/params-arrays"
Expand Down Expand Up @@ -1749,10 +1786,18 @@
"source_path_from_root": "/docs/csharp/misc/cs1016.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch"
},
{
"source_path_from_root": "/docs/csharp/misc/cs1020.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
},
{
"source_path_from_root": "/docs/csharp/misc/cs1104.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/params-arrays"
},
{
"source_path_from_root": "/docs/csharp/misc/cs1007.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
},
{
"source_path_from_root": "/docs/csharp/misc/cs1510.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/ref-modifiers-errors"
Expand Down Expand Up @@ -1825,6 +1870,14 @@
"source_path_from_root": "/docs/csharp/misc/cs1632.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/lambda-expression-errors#syntax-limitations-in-lambda-expressions"
},
{
"source_path_from_root": "/docs/csharp/misc/cs1534.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
},
{
"source_path_from_root": "/docs/csharp/misc/cs1535.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
},
{
"source_path_from_root": "/docs/csharp/misc/cs1637.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/iterator-yield"
Expand Down Expand Up @@ -1873,6 +1926,14 @@
"source_path_from_root": "/docs/csharp/misc/cs1925.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
},
{
"source_path_from_root": "/docs/csharp/misc/cs1928.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
},
{
"source_path_from_root": "/docs/csharp/misc/cs1929.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
},
{
"source_path_from_root": "/docs/csharp/misc/cs1939.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/ref-modifiers-errors"
Expand All @@ -1885,6 +1946,10 @@
"source_path_from_root": "/docs/csharp/misc/cs1945.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
},
{
"source_path_from_root": "/docs/csharp/misc/cs1950.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
},
{
"source_path_from_root": "/docs/csharp/misc/cs1951.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
Expand All @@ -1901,6 +1966,10 @@
"source_path_from_root": "/docs/csharp/misc/cs1954.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
},
{
"source_path_from_root": "/docs/csharp/misc/cs3006.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overload-resolution"
},
{
"source_path_from_root": "/docs/csharp/misc/cs3016.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ f1_keywords:
- "CS0820"
- "CS0826"
- "CS0846"
- "CS1062"
- "CS1063"
- "CS1064"
- "CS1552"
- "CS1586"
- "CS1920"
- "CS1921"
- "CS1925"
- "CS1950"
- "CS1954"
- "CS3007"
- "CS3016"
Expand Down Expand Up @@ -49,9 +53,13 @@ helpviewer_keywords:
- "CS0846"
- "CS1552"
- "CS1586"
- "CS1062"
- "CS1063"
- "CS1064"
- "CS1920"
- "CS1921"
- "CS1925"
- "CS1950"
- "CS1954"
- "CS3007"
- "CS3016"
Expand Down Expand Up @@ -86,11 +94,13 @@ That's by design. The text closely matches the text of the compiler error / warn
- [**CS0820**](#invalid-element-type): *Cannot assign array initializer to an implicitly typed local*
- [**CS0826**](#invalid-element-type): *No best type found for implicitly typed array.*
- [**CS0846**](#invalid-array-initializer): *A nested array initializer is expected*
- [**CS1063**](#invalid-collection-initializer): *The best overloaded Add method for the collection initializer element is obsolete.*
- [**CS1552**](#invalid-array-rank): *Array type specifier, `[]`, must appear before parameter name*
- [**CS1586**](#invalid-array-length): *Array creation must have array size or array initializer*
- [**CS1920**](#invalid-collection-initializer): *Element initializer cannot be empty.*
- [**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.*
- [**CS1925**](#invalid-array-initializer): *Cannot initialize object of type 'type' with a collection initializer.*
- [**CS1950**](#invalid-collection-initializer): *The best overloaded Add method for the collection initializer has some invalid arguments.*
- [**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.*
- [**CS9174**](#invalid-collection-initializer): *Cannot initialize type with a collection literal because the type is not constructible.*
- [**CS9176**](#invalid-collection-initializer): *There is no target type for the collection literal.*
Expand All @@ -103,6 +113,8 @@ That's by design. The text closely matches the text of the compiler error / warn

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

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

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

The compiler might also generate the following warning:

- **CS1062**: *The best overloaded Add method for the collection initializer element is obsolete.*
- **CS1064**: *The best overloaded Add method for the collection initializer element is obsolete.*
- **CS9208**: *Collection expression may incur unexpected heap allocations. Consider explicitly creating an array, then converting to the final type to make the allocation explicit.*
- **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.*

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

- 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.
- A collection initializer that includes braces (`{` and `}`) can't be empty.
- The class must implement IEnumerable and have a public `Add` method.
- 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.
- Overload resolution must pick one `Add` method as a better match. There can't be multiple matching methods that are equally good.
- 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.
Expand Down
107 changes: 0 additions & 107 deletions docs/csharp/language-reference/compiler-messages/cs0034.md

This file was deleted.

Loading
Loading