Skip to content
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

Add syntax grammar for allows constraint to ref-struct-interfaces.md #7977

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions proposals/ref-struct-interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,58 @@ Detailed Notes:

### ref struct Generic Parameters

```ANTLR
type_parameter_constraints_clause
: 'where' type_parameter ':' type_parameter_constraints
;

type_parameter_constraints
: restrictive_type_parameter_constraints
| allows_type_parameter_constraints_clause
| restrictive_type_parameter_constraints ',' allows_type_parameter_constraints_clause

restrictive_type_parameter_constraints
: primary_constraint
| secondary_constraints
| constructor_constraint
| primary_constraint ',' secondary_constraints
| primary_constraint ',' constructor_constraint
| secondary_constraints ',' constructor_constraint
| primary_constraint ',' secondary_constraints ',' constructor_constraint
;

primary_constraint
: class_type
| 'class'
| 'struct'
| 'unmanaged'
;

secondary_constraints
: interface_type
| type_parameter
| secondary_constraints ',' interface_type
| secondary_constraints ',' type_parameter
;

constructor_constraint
: 'new' '(' ')'
;

allows_type_parameter_constraints_clause
: 'allows' allows_type_parameter_constraints

allows_type_parameter_constraints
: allows_type_parameter_constraint
| allows_type_parameter_constraints ',' allows_type_parameter_constraint
Copy link
Member

Choose a reason for hiding this comment

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

Why allow multiple if we have just single option now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why allow multiple if we have just single option now?

Future proofing, we might want to allow more things in the future.


allows_type_parameter_constraint
: ref_struct_clause

ref_struct_clause
: 'ref' 'struct'
```

The language will allow for generic parameters to opt into supporting `ref struct` as arguments by using the `allows ref struct` syntax inside a `where` clause:

```csharp
Expand Down