You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a mock is generated, the constraints from a generic interface method are copied to the explicit interface implementation which causes the compiler error CS0460: Constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly, except for either a 'class', or a 'struct' constraint., when there are constraints other than class and struct.
Expected Behavior
The source generator does not copy constraints from the interface. If a generic type parameter is unconstrained, the default constraint should still be used (see #5362)
Actual Behavior
The constraints are copied to the explicit interface implementation causing CS0460
Steps to Reproduce
usingTUnit.Mocks.Generated.Sandbox;namespaceSandbox;publicinterfaceIFoo{TGet<T>(stringkey)whereT:notnull;// or any other constraint like `unmanaged`, `new()`, `<base type>`...}publicclassTestClass{[Test]publicasyncTaskSomeTest(){IFooMockmockInt=IFoo.Mock();// CS0460}}
TUnit Version
1.28.0-beta
.NET Version
.NET 10.0
Operating System
Windows
IDE / Test Runner
JetBrains Rider
Error Output / Stack Trace
Restore complete (0.8s)
Sandbox net10.0 failed with 1 error(s) (0.6s)
/mnt/x/Sandbox/Sandbox/obj/Debug/net10.0/TUnit.Mocks.SourceGenerator/TUnit.Mocks.SourceGenerator.MockGenerator/Sandbox_IFoo_Mock.g.cs(12,61): error CS0460: Constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly, except for either a 'class', or a 'struct' constraint.
Build failed with 1 error(s) in 1.8s
Additional Context
No response
IDE-Specific Issue?
I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE
Description
When a mock is generated, the constraints from a generic interface method are copied to the explicit interface implementation which causes the compiler error
CS0460: Constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly, except for either a 'class', or a 'struct' constraint., when there are constraints other thanclassandstruct.Expected Behavior
The source generator does not copy constraints from the interface. If a generic type parameter is unconstrained, the
defaultconstraint should still be used (see #5362)Actual Behavior
The constraints are copied to the explicit interface implementation causing
CS0460Steps to Reproduce
TUnit Version
1.28.0-beta
.NET Version
.NET 10.0
Operating System
Windows
IDE / Test Runner
JetBrains Rider
Error Output / Stack Trace
Additional Context
No response
IDE-Specific Issue?
dotnet testordotnet run, not just in my IDE