Skip to content

Conversation

oising
Copy link

@oising oising commented May 12, 2025

Description

The actor source generator will now correctly add any type constraints to the client class. Supported:

  • where T: class
  • where T: struct
  • where T: unmanaged
  • where T: <class or interface>
  • where T: new()
  • where T: notnull

...and any legal combinations thereof.

I've added tests for a single case (single type parameter and one constraint) and a complex case (multiple type parametes and constraints.)

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #1534

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

@oising oising requested review from a team as code owners May 12, 2025 17:55
Signed-off-by: Oisin Grehan <[email protected]>
@oising oising force-pushed the actor-srcgen-generic-constraints branch from aa000f9 to 087f11b Compare May 12, 2025 17:58
@oising oising force-pushed the actor-srcgen-generic-constraints branch from 1fb41e7 to 435933c Compare May 12, 2025 18:06
@Copilot Copilot AI review requested due to automatic review settings August 7, 2025 16:36
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for generic type constraints to the Actor source generator, enabling it to properly handle and generate constraint clauses for generic actor interfaces. The generator now correctly preserves constraints like where T: class, where T: struct, where T: unmanaged, interface constraints, where T: new(), and where T: notnull when creating actor client classes.

  • Implemented constraint clause generation for all supported generic constraint types
  • Added logic to iterate through type parameters and build appropriate constraint syntax
  • Added comprehensive test coverage for both single and multiple type parameter scenarios

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Dapr.Actors.Generators/ActorClientGenerator.cs Implements constraint clause generation logic for generic type parameters in the actor client generator
test/Dapr.Actors.Generators.Test/ActorClientGeneratorTests.cs Adds test cases for single and multiple type parameter constraints to verify the generator works correctly

// Add unmanaged constraint
if (typeParam.HasUnmanagedTypeConstraint)
{
constraints.Add(SyntaxFactory.TypeConstraint(SyntaxFactory.IdentifierName("unmanaged")));
Copy link
Preview

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

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

The unmanaged constraint should be added before type constraints but after class/struct constraints. The current order may not follow C# constraint ordering requirements where 'unmanaged' should come before interface constraints.

Copilot uses AI. Check for mistakes.

Copy link
Author

Choose a reason for hiding this comment

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

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.

Actor source generator does not copy generic constraints for type parameters
2 participants