Skip to content

Valid code doesn't compile in Release mode #1264

@OkayX6

Description

@OkayX6

I have a perfectly valid code that doesn't compile in Release mode, when defining value let subStr in the code below.

Repro steps

  • Create empty console application
  • Add reference to FSharp.Data 2.3.0
  • Copy-paste the following code into Program.fs:
open FSharp.Data

type StatsResponse = JsonProvider<"""[
  {
    "yesCount": 983,
    "moyCount": 458,
    "noCount": 280,
    "alertCount": 3,
    "idSection": 94,
    "sectionName": "Section A"
  }]""">

type Stats(sectionStats: StatsResponse.Root[]) = 
    let sectionIdToStatsMap =
        sectionStats
        |> Seq.map (fun stats -> stats.IdSection, stats)
        |> dict

    member val SectionStats = sectionIdToStatsMap.Values

let generateReportFromStats (clientStats: #seq<string * Stats>) =
    clientStats
    |> Seq.iter (fun (clientName, stats) ->
        // BUG: it works when swapping the two following lines
        let orderedStats = stats.SectionStats
        let subStr = clientName.Substring(23)

        for s in orderedStats do
            printfn "%s" subStr
    )

[<EntryPoint>]
let main argv = 
    printfn "%A" argv
    0 // return an integer exit code
  • Try to compile...

Expected behavior

Code should compile.

Actual behavior

Code doesn't compile with error: Undefined value 'subStr : string'

Known workarounds

Swap the two lines that start by: let subStr and let orderedStats.

Related information

  • Windows 10 Pro
  • F# 4.0
  • .NET 4.6
  • Visual Studio Enterprise 2015

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions