Skip to content

[Version 11.0] Feature support for static abstract members in interfaces#1609

Draft
RexJaeschke wants to merge 6 commits intodraft-v11from
v11-static-abstract-members-in-interfaces
Draft

[Version 11.0] Feature support for static abstract members in interfaces#1609
RexJaeschke wants to merge 6 commits intodraft-v11from
v11-static-abstract-members-in-interfaces

Conversation

@RexJaeschke
Copy link
Contributor

@RexJaeschke RexJaeschke commented Mar 17, 2026

This is Rex's adaptation of the corresponding MS proposal.

Issue

The MS spec contains a section called “Pattern matching.” In there, a change to constant patterns is proposed. However, I cannot find the text below they propose augmenting, anywhere in the spec

A constant pattern tests the value of an expression against a constant value. The constant may be any constant expression, such as a literal, the name of a declared const variable, or an enumeration constant. When the input value is not an open type, the constant expression is implicitly converted to the type of the matched expression; if the type of the input value is not pattern-compatible with the type of the constant expression, the pattern-matching operation is an error. If the constant expression being matched against is a numeric value, the input value is a type that inherits from System.Numerics.INumberBase<T>, and there is no constant conversion from the constant expression to the type of the input value, the pattern-matching operation is an error.

Note that the proposed new text refers to System.Numerics.INumberBase<T>, which I mention elsewhere in the PR as needing attention.

@RexJaeschke RexJaeschke added this to the C# 11 milestone Mar 17, 2026
@RexJaeschke RexJaeschke added type: feature This issue describes a new feature Review: pending Proposal is available for review labels Mar 17, 2026
@RexJaeschke RexJaeschke marked this pull request as draft March 17, 2026 17:58
It is a compile-time error if *constant_expression*is `double.NaN`, `float.NaN`, or `null_literal`.

When the input value has a type for which a suitable built-in binary relational operator is defined, the evaluation of that operator is taken as the meaning of the relational pattern. Otherwise, the input value is converted to the type of `constant_expression` using an explicit nullable or unboxing conversion. It is a compile-time error if no such conversion exists. The pattern is considered to not match if the conversion fails. If the conversion succeeds, the result of the pattern-matching operation is the result of evaluating the expression `e «op» v` where `e` is the converted input, «op» is the relational operator, and `v` is the `constant_expression`.
When the input value has a type for which a suitable built-in binary relational operator is defined, the evaluation of that operator is taken as the meaning of the relational pattern. Otherwise, the input value is converted to the type of *constant_expression* using an explicit nullable or unboxing conversion. It is a compile-time error if no such conversion exists. It is a compile-time error if the input type is a type parameter constrained to, or a type inheriting, from `System.Numerics.INumberBase<T>` and the input type has no suitable built-in binary relational operator defined. The pattern is considered to not match if the conversion fails. If the conversion succeeds, the result of the pattern-matching operation is the result of evaluating the expression `e «op» v` where `e` is the converted input, «op» is the relational operator, and `v` is the *constant_expression*.
Copy link
Contributor Author

@RexJaeschke RexJaeschke Mar 17, 2026

Choose a reason for hiding this comment

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

This is the first mention of the type System.Numerics.INumberBase<T> in the spec. Unless we are going to add all the machinery about that type and how built-in numeric types now have that as a base interface, we'll need some alternative wording here.

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.

1 participant