csharp-algebraictypes
csharp-algebraictypes copied to clipboard
If parametrized value is struct type, GetHashCode show an error
Description
For union's choices with non-generic parameter, if the parameter is struct, compiler shows an error.
Repro steps
Please provide the steps required to reproduce the problem
- Create csunion file like this:
namespace Test.Unions
{
union Choice
{
Contains<bool>
}
}
- Step B
Save the file. open the g.cs file and check the GetHashCode method in the Contains class.
Expected behavior
I think the created class should check if the type is class or struct.
Actual behavior
Not checking.
Known workarounds
Editing the g.cs file is the only one workaround, but if the csunion is edited, the changes will be lost.
EDIT: use nullable tipes:
namespace Test.Unions
{
union Choice
{
Contains<bool?>
}
}
A workaround that I found is to use nullable types. int? insteand int, bool? insteand bool.