Skip to content

Setup for C# 11#28498

Merged
BillWagner merged 9 commits intodotnet:mainfrom
BillWagner:better-breaking-changes
Mar 7, 2022
Merged

Setup for C# 11#28498
BillWagner merged 9 commits intodotnet:mainfrom
BillWagner:better-breaking-changes

Conversation

@BillWagner
Copy link
Copy Markdown
Member

@BillWagner BillWagner commented Mar 4, 2022

Fixes #28442
Fixes #28446

Two sets of changes to improve adoption of new features.

First move features currently in preview from the C# 10 what's new page to the C# 11 what's new page.

Second, add details on the latest (and upcoming) breaking changes in the compiler

Internal Preview links:

Breaking changes
C# 10
C# 11

Move the features currently in Preview to the new C# 11 page.
In this commit, add troubleshooting information on compiler breaking changes.
Co-authored-by: David Pine <david.pine@microsoft.com>
Beginning with the .NET 6.0.200 SDK or Visual Studio 2022 version 17.1, preview features in C# are available for you to try.

> [!IMPORTANT]
> These are currently preview features. You must [set `<LangVersion>` to `Preview`](../language-reference/compiler-options/language.md#langversion) to enable these features. Any feature may change before its final release. These features may not all be released in C# 11. Some may remain in a preview phase for longer based on feedback on the feature.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We typically use lower-cased "preview" for <LangVersion>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"These are currently preview features. You must ..." is duplicated. Looks like a copy&paste mistake.

Copy link
Copy Markdown
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks (iteration 4) modulo typos

Co-authored-by: Charles Stoner <10732005+cston@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@KathleenDollard KathleenDollard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome. I would like to see error numbers in the breaking changes where an error may occur, and perhaps exact text. Maybe not in the header if you think this is not the most important way people will encounter an error.


To address the issue, in .NET SDK 6.0.200 (VS 17.1) the compiler no longer synthesizes a parameterless constructor. If a `struct` contains field initializers and no explicit constructors, the compiler generates an error. If a `struct` has field initializers it must declare a constructor, because otherwise the field initializers are never executed.

Additionally, all fields must be definitely assigned in `struct` constructors that do not have a `: this()` initializer, so any previously unassigned fields must be assigned from the constructor or from field initializers.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is a "previously unassigned field" here? (IOW, what other than initializers and constructors might initialize them?)

Copy link
Copy Markdown
Contributor

@cston cston Mar 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Previously unassigned" was meant as "not assigned in code compiled with 17.0". I've added a suggested change below to try to clarify.

Co-authored-by: Charles Stoner <10732005+cston@users.noreply.github.com>
@BillWagner BillWagner merged commit f86cf8f into dotnet:main Mar 7, 2022
@BillWagner BillWagner deleted the better-breaking-changes branch March 7, 2022 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move preview features from C# 10 to C# 11 Better breaking changes

6 participants