daver32 / InterfaceGenerator

A simple source generator that creates interfaces by implementations.
MIT License
36 stars 14 forks source link

Fix handling of unmanaged type parameter constraint #22

Open rkonklewski-am2m opened 1 year ago

rkonklewski-am2m commented 1 year ago

When a method had the 'unmanaged' constraint specified, then the interface generator would output both 'struct' and 'unmanaged' constraints. However, the C# specification explicitly forbids to combine these constraints.

The problem is that when the HasUnmanagedTypeConstraint property of ITypeParameterSymbol is true, then HasValueTypeConstraint is also true. To fix the issue the class / struct / unmanaged / notnull constraints need to be treated as mutually exclusive, and unmanaged needs to be checked before struct.