Skip to content

Conversation

@BillWagner
Copy link
Member

@BillWagner BillWagner commented Nov 7, 2025

It is quite possible that some members will think that some (maybe a lot) of the text is "implementation detail," which should be discarded and (presumably) replaced with some minimal wording.

All commits from #983 have been squashed and added to this PR.

This PR / feature makes numerous changes to the grammar. We still need corresponding updates to the test and validation suite.

The following notes are carried over for additional work needed:

A. I put the new subclause "With expression" prior to "Arithmetic operators", which once the V8 features "Indices and Ranges" and "Pattern matching" have been merged, should immediately follow "Range operator" and "Switch expression." Make sure these are all in the correct place. 12.4.2 Operator precedence and associativity will also need to be revised accordingly.

B. New subclause §rec-class-prtmem Printing members mentions a method System.Runtime.CompilerServices.RuntimeHelpers.EnsureSufficientExecutionStack(). It's quite possible that this is an implementation-specific detail, in which case, we'll need to find words to make it abstract, and possibly update the Portability annex accordingly.

Add support for record classes

Add files via upload

Add support for record classes

Add support for record classes

fix markup

fix markdown formatting

fix markdown formatting

fix link

another missed link
@BillWagner BillWagner changed the title Feature support for records [Version 9.0] Feature support for records Nov 7, 2025
@RexJaeschke RexJaeschke added this to the C# 9.0 milestone Nov 8, 2025

An awaiter’s implementation of the interface methods `INotifyCompletion.OnCompleted` and `ICriticalNotifyCompletion.UnsafeOnCompleted` should cause the delegate `r` to be invoked at most once. Otherwise, the behavior of the enclosing async function is undefined.

## §with-expressions With expressions
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to add "with" as a new row to the table in the (earlier) section "Operator precedence and associativity." And as we have historically organized the sections in this clause in descending precedence order, we might need to move this new section up or down, accordingly.

Comment on lines +22 to +24
class_tag
: 'class'
| 'record'
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI: In V9, record means record class but we can't say that explicitly. In V10, this is permitted and we'll replace these 2 rules with 'record'? 'class'.


A *class_declaration* is a *type_declaration* ([§14.7](namespaces.md#147-type-declarations)) that declares a new class.

```ANTLR
Copy link
Contributor

@RexJaeschke RexJaeschke Nov 8, 2025

Choose a reason for hiding this comment

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

Heads up grammarians! As you will see below, I have a generous syntax for a class in which not all combinations are permitted, and those combinations are described in text as constraints. (For example, a record class can have a delimited_parameter_list while a non-record class cannot. And for a record class, class_modifier shall not be static.) Yes, we could try to break this up into separate rules for record classes and non-record classes to eliminate some (but maybe not all) of those constraints. However, there will be tweaks to this grammar in future versions; specifically:

  • V10 allows record class as well as record.
  • V10 supports record struct.
  • V12 allows a primary constructor (which uses delimited_parameter_list) on non-record classes and structs.

which means that extra work done now to make the grammar rules more complete likely will be (at least partially) undone in future revs.


The method performs the following tasks:

1. Calls the method `System.Runtime.CompilerServices.RuntimeHelpers.EnsureSufficientExecutionStack()` if that method is present and the record class has printable members.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really want to expose this type in the spec?

Tweaks I made when comparing this PR with what I researched 2+ years ago.
@RexJaeschke RexJaeschke added the Review: pending Proposal is available for review label Nov 8, 2025
@RexJaeschke RexJaeschke added the type: feature This issue describes a new feature label Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review: pending Proposal is available for review type: feature This issue describes a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants