csharp-algebraictypes icon indicating copy to clipboard operation
csharp-algebraictypes copied to clipboard

If parametrized value is struct type, GetHashCode show an error

Open desarrollo03TR opened this issue 7 years ago • 1 comments

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

  1. Create csunion file like this:
namespace Test.Unions
{
	union Choice
	{
		Contains<bool>
	}
}
  1. 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?>
	}
}

desarrollo03TR avatar Dec 27 '17 22:12 desarrollo03TR

A workaround that I found is to use nullable types. int? insteand int, bool? insteand bool.

desarrollo03TR avatar Aug 22 '19 15:08 desarrollo03TR