-
Notifications
You must be signed in to change notification settings - Fork 6k
Define "defining declaration" and enhance CS0759 compiler error documentation #47628
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e534278
Initial plan
Copilot 0dab670
Add detailed explanation and examples for CS0759 compiler error
Copilot b5bc3ac
Update target framework to .NET 9 in partial-declarations project
Copilot db209a3
Address review feedback: simplify CS0759 explanation and fix code com…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...harp/language-reference/compiler-messages/snippets/partial-declarations/CS0759Examples.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
|
||
namespace CS0759Examples | ||
{ | ||
// <IncorrectExample> | ||
// This will cause CS0759: No defining declaration found for implementing declaration of partial method | ||
BillWagner marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// Uncomment the class below to see the CS0759 error: | ||
/* | ||
public partial class ExampleClass | ||
{ | ||
// ERROR: This is an implementing declaration without a corresponding defining declaration | ||
partial void MyMethod() // CS0759 | ||
{ | ||
Console.WriteLine("Implementation without definition"); | ||
} | ||
} | ||
*/ | ||
// </IncorrectExample> | ||
|
||
// <CorrectExample> | ||
// Correct way: Provide both the defining declaration and implementing declaration | ||
public partial class CorrectExampleClass | ||
{ | ||
// Defining declaration (signature without body) | ||
partial void MyMethod(); | ||
} | ||
|
||
public partial class CorrectExampleClass | ||
{ | ||
// Implementing declaration (signature with body) | ||
partial void MyMethod() | ||
{ | ||
Console.WriteLine("This works correctly"); | ||
} | ||
} | ||
// </CorrectExample> | ||
|
||
// <AlternativeCorrect> | ||
// Alternative correct approach: defining and implementing in same partial class | ||
public partial class AlternativeExampleClass | ||
{ | ||
// Defining declaration | ||
partial void MyMethod(); | ||
|
||
// Implementing declaration in same partial class section | ||
partial void MyMethod() | ||
{ | ||
Console.WriteLine("This also works correctly"); | ||
} | ||
} | ||
// </AlternativeCorrect> | ||
} |
8 changes: 8 additions & 0 deletions
8
...age-reference/compiler-messages/snippets/partial-declarations/partial-declarations.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
BillWagner marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.