Skip to content

Commit

Permalink
Document compiler errors and warnings for method parameter / argument…
Browse files Browse the repository at this point in the history
… mismatch (dotnet#38797)

* create stub for CS7036

* build warning

* stash this.

This may be the wrong list of items to add to this page.

* finish consolidating articles

* fix build warning

* edit text

* grammar check

* updated redirected links

* fix one link

* Apply suggestions from code review

Co-authored-by: Tom Dykstra <[email protected]>

---------

Co-authored-by: Tom Dykstra <[email protected]>
  • Loading branch information
BillWagner and tdykstra authored Dec 20, 2023
1 parent 7875330 commit 5e3a054
Show file tree
Hide file tree
Showing 20 changed files with 257 additions and 591 deletions.
52 changes: 52 additions & 0 deletions .openpublishing.redirection.csharp.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,22 @@
"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/cs1739.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1740.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1741.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/ref-modifiers-errors"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1742.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1921.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
Expand Down Expand Up @@ -419,6 +431,10 @@
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs8892.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/warning-waves#cs8892"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs8964.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-options/addmodule-compiler-option.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-options/inputs"
Expand Down Expand Up @@ -1332,6 +1348,10 @@
"source_path_from_root": "/docs/csharp/misc/cs0171.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/feature-version-errors"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0182.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0192.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/ref-modifiers-errors"
Expand Down Expand Up @@ -1400,10 +1420,22 @@
"source_path_from_root": "/docs/csharp/misc/cs0576.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/using-directive-errors"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0591.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0599.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0611.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0617.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0623.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
Expand All @@ -1412,6 +1444,18 @@
"source_path_from_root": "/docs/csharp/misc/cs0631.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/ref-modifiers-errors"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0633.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0643.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch"
},
{
"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/cs0687.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/using-directive-errors"
Expand Down Expand Up @@ -1460,6 +1504,14 @@
"source_path_from_root": "/docs/csharp/misc/cs0838.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0839.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch"
},
{
"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/cs1510.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/ref-modifiers-errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ f1_keywords:
- "CS8054" # ERR_EnumsCantContainDefaultConstructor
- "CS8091" # ERR_ExternHasConstructorInitializer
- "CS8358" # ERR_AttributeCtorInParameter
- "CS8861"
- "CS8862" # ERR_UnexpectedOrMissingConstructorInitializerInRecord
- "CS8867" # ERR_NoCopyConstructorInBaseType
- "CS8868" # ERR_CopyConstructorMustInvokeBaseCopyConstructor
Expand Down Expand Up @@ -58,6 +59,7 @@ helpviewer_keywords:
- "CS8054"
- "CS8091"
- "CS8358"
- "CS8861"
- "CS8862"
- "CS8867"
- "CS8868"
Expand Down Expand Up @@ -107,6 +109,7 @@ That's by design. The text closely matches the text of the compiler error / warn
- [**CS0768**](#constructor-calls-with-base-and-this): *Constructor cannot call itself through another constructor.*
- [**CS8054**](#constructor-declaration): *Enums cannot contain explicit parameterless constructors.*
- [**CS8091**](#constructor-declaration): *cannot be extern and have a constructor initializer.*
- [**CS8861**](#primary-constructor-declaration): *Unexpected argument list.*
- [**CS8862**](#primary-constructor-declaration): *A constructor declared in a type with parameter list must have 'this' constructor initializer.*
- [**CS8358**](#constructor-declaration): *Cannot use attribute constructor because it has 'in' parameters.*
- [**CS8867**](#records-and-copy-constructors): *No accessible copy constructor found in base type '{0}'.*
Expand Down Expand Up @@ -234,6 +237,7 @@ Adding the `record` modifier to a `struct` or `class` type creates a [record](..

The compiler emits the following errors when a primary constructor violates one or more rules on primary constructors for classes and structs:

- **CS8861**: *Unexpected argument list.*
- **CS8862**: *A constructor declared in a type with parameter list must have 'this' constructor initializer.*
- **CS9105**: *Cannot use primary constructor parameter in this context.*
- **CS9106**: *Identifier is ambiguous between type and parameter in this context.*
Expand Down Expand Up @@ -275,6 +279,8 @@ Readonly only struct types have the following extra restrictions on primary cons

In all these cases, the restrictions on primary constructor parameters are consistent with restrictions on data fields in those types. The restrictions are because a primary constructor parameter may be transformed into a synthesized field in the type. Therefore primary constructor parameters must follow the rules that apply to that synthesized field.

A derived primary constructor calls the base primary constructor by supplying the parameters to the base constructor. You must use the parameter names from the derived constructor declaration.

The warnings provide guidance on captured or shadowed primary constructor parameters.

- **CS9107**: *Parameter is captured into the state of the enclosing type and its value is also passed to the base constructor. The value might be captured by the base class as well.* This warning indicates that your code may be allocated two copies of a primary constructor parameter. Because the parameter is passed to the base class, the base class likely uses it. Because the derived class accesses it, it may have a second copy of the same parameter. That extra storage may not be intended.
Expand Down
44 changes: 0 additions & 44 deletions docs/csharp/language-reference/compiler-messages/cs1739.md

This file was deleted.

40 changes: 0 additions & 40 deletions docs/csharp/language-reference/compiler-messages/cs1740.md

This file was deleted.

42 changes: 0 additions & 42 deletions docs/csharp/language-reference/compiler-messages/cs1742.md

This file was deleted.

40 changes: 0 additions & 40 deletions docs/csharp/language-reference/compiler-messages/cs8964.md

This file was deleted.

Loading

0 comments on commit 5e3a054

Please sign in to comment.