fsprojects / FsLexYacc

Lexer and parser generators for F#
http://fsprojects.github.io/FsLexYacc/
MIT License
203 stars 68 forks source link

removing the need for explicit numbering of enums in F#, possible fixing problem with struct decorated DU's without fields. #173

Open kam1986 opened 8 months ago

kam1986 commented 8 months ago

Description

In the process of optimizing some of my code, I noticed the problem where

[<Struct>]
type Tag =
     | Case0
          :
     | CaseN

Coursed the compiler to throw a compiler exception

System.InvalidProgramException: Common Language Runtime detected an invalid program

For any DU type where N >= 49 (50 cases)

I also noticed that the interpreter and compiler transform Enums (DUs' with assigned values) are converted into struct DUs', and they are not throwing the exception above.

Why is it, that fieldless DU's just are handled as enums? This seems like a rather simple workaround. the type inference system, should already have enough information to catch this and let the compiler make that choice. It would make enums where the value of a case are not important much simpler to implement, and solve the above problem.