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

C# 13: Allows ref struct. #18385

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

michaelnebel
Copy link
Contributor

@michaelnebel michaelnebel commented Jan 2, 2025

In this PR we introduce support for the allows ref struct type parameter constraint. The language feature is described here.

A couple of notes on the implementation.

  • A ref struct type can not be implicitly converted to a dynamic type, object or ValueType.
  • The allows ref struct is a negative constraint meaning that it extends the number of types that can be used as type replacement for a type parameter.

The unification and dispatch call logic has been adapted to take the allows ref struct constraint into account (relevant for dynamic dispatch) for deciding relevant dispatch targets. To make things easier a new class RefStruct has been introduced in the type hierarcy. One could consider whether we want to change the type hierarchy such that RefStruct doesn't extend Struct (and thereby ValueType). Not sure whether this is worth it.

Furthermore, we also extract the notnull general type parameter constraint.

@github-actions github-actions bot added the C# label Jan 2, 2025
@michaelnebel michaelnebel force-pushed the csharp/allowsrefstruct branch from fd26958 to d336e1d Compare January 3, 2025 14:36
@michaelnebel michaelnebel force-pushed the csharp/allowsrefstruct branch from d336e1d to caaf291 Compare January 3, 2025 15:28
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.

1 participant