Skip to content

struct DU with more than 48 cases causes generation of an invalid program #5342

@rosecodym

Description

@rosecodym

Repro steps

Build this program:

[<Struct>]
type Country =
    | Unknown
    | Andorra
    | UnitedArabEmirates
    | Afghanistan
    | AntiguaAndBarbuda
    | Anguilla
    | Albania
    | Armenia
    | NetherlandsAntilles
    | Angola
    | Argentina
    | AmericanSamoa
    | Austria
    | Australia
    | Aruba
    | AlandIslands
    | Azerbaijan
    | BosniaAndHerzegovina
    | Barbados
    | Bangladesh
    | Belgium
    | BurkinaFaso
    | Bulgaria
    | Bahrain
    | Burundi
    | Benin
    | SaintBarthelemy
    | Bermuda
    | BruneiDarussalam
    | Bolivia
    | Brazil
    | Bahamas
    | Bhutan
    | BouvetIsland
    | Botswana
    | Belarus
    | Belize
    | Canada
    | CocosIslands
    | Congo
    | CentralAfricanRepublic
    | CongoBrazzaville
    | Switzerland
    | IvoryCoast
    | CookIslands
    | Chile
    | Cameroon
    | China
    | Colombia
    | HongKong

[<EntryPoint>]
let main argv =
    printfn "Hong Kong: %A" HongKong
    0

using this .fsproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="Program.fs" />
  </ItemGroup>

</Project>

(Targeting netcoreapp2.1 instead of net461 doesn't make any difference; neither does whether I build as Debug or Release. I didn't play around with specific optimization settings.)

Expected behavior

Hong Kong: HongKong should be printed to the console.

Actual behavior

This unhandled exception:

Unhandled Exception: System.InvalidProgramException: Common Language Runtime detected an invalid program.
   at Program.Country.get_HongKong()
   at Program.main(String[] argv)

Known workarounds

If you remove any of the DU cases, or remove [<Struct>], the problem won't appear.

Related information / Severity

I know this is kind of an outlandish case; I discovered it while just throwing stuff at a wall during some early performance exploration. But it seemed worth reporting anyway.

VS 15.7.5
Visual F# Tools 10.1 for F# 4.1 15.7.0.0 173513e.

The output of dotnet --info:

.NET Core SDK (reflecting any global.json):
 Version:   2.1.300
 Commit:    adab45bf0c

Runtime Environment:
 OS Name:     Windows
 OS Version:  6.1.7601
 OS Platform: Windows
 RID:         win7-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.300\

Host (useful for support):
  Version: 2.1.0
  Commit:  caa7b7e2ba

.NET Core SDKs installed:
  1.0.0 [C:\Program Files\dotnet\sdk]
  2.0.1-servicing-006933 [C:\Program Files\dotnet\sdk]
  2.0.2 [C:\Program Files\dotnet\sdk]
  2.0.3 [C:\Program Files\dotnet\sdk]
  2.1.2 [C:\Program Files\dotnet\sdk]
  2.1.4 [C:\Program Files\dotnet\sdk]
  2.1.101 [C:\Program Files\dotnet\sdk]
  2.1.104 [C:\Program Files\dotnet\sdk]
  2.1.200 [C:\Program Files\dotnet\sdk]
  2.1.201 [C:\Program Files\dotnet\sdk]
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.300 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 1.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

Metadata

Metadata

Assignees

Labels

Area-Diagnosticsmistakes and possible improvements to diagnosticsBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.

Type

No type
No fields configured for issues without a type.

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions