diff --git a/src/absil/il.fs b/src/absil/il.fs index 09cdbd5d326..3b475f672bc 100644 --- a/src/absil/il.fs +++ b/src/absil/il.fs @@ -309,6 +309,10 @@ type ILVersionInfo = new (major, minor, build, revision) = { Major = major; Minor = minor; Build = build; Revision = revision } + /// For debugging + override x.ToString() = sprintf "ILVersionInfo: %u %u %u %u" (x.Major) (x.Minor) (x.Build) (x.Revision) + + type Locale = string [] diff --git a/src/fsharp/fsc.fs b/src/fsharp/fsc.fs index 7bb43066689..01025f3a349 100644 --- a/src/fsharp/fsc.fs +++ b/src/fsharp/fsc.fs @@ -837,11 +837,24 @@ module MainModuleBuilder = v let productVersionToILVersionInfo (version: string) : ILVersionInfo = - let parseOrZero v = match System.UInt16.TryParse v with (true, i) -> i | (false, _) -> 0us + let parseOrZero i (v:string) = + let v = + // When i = 3 then this is the 4th part of the version. The last part of the version can be trailed by any characters so we trim them off + if i <> 3 then + v + else + ((false, ""), v) + ||> Seq.fold(fun (finished, v) c -> + match finished with + | false when Char.IsDigit(c) -> false, v + c.ToString() + | _ -> true, v) + |> snd + match System.UInt16.TryParse v with + | (true, i) -> i + | (false, _) -> 0us let validParts = version.Split('.') - |> Seq.map parseOrZero - |> Seq.takeWhile ((<>) 0us) + |> Array.mapi(fun i v -> parseOrZero i v) |> Seq.toList match validParts @ [0us; 0us; 0us; 0us] with | major :: minor :: build :: rev :: _ -> ILVersionInfo(major, minor, build, rev) diff --git a/tests/FSharp.Compiler.UnitTests/ProductVersion.fs b/tests/FSharp.Compiler.UnitTests/ProductVersion.fs index 1da55436d25..aa2d1168898 100644 --- a/tests/FSharp.Compiler.UnitTests/ProductVersion.fs +++ b/tests/FSharp.Compiler.UnitTests/ProductVersion.fs @@ -59,6 +59,8 @@ module ProductVersionTest = let validValues () = let max = System.UInt16.MaxValue [ "1.2.3.4", ILVersionInfo(1us,2us,3us,4us) + "1.0.3.4", ILVersionInfo(1us,0us,3us,4us) + "7.0.0.4-SomeExtraInformation", ILVersionInfo(7us,0us,0us,4us) "0.0.0.0", ILVersionInfo(0us,0us,0us,0us) "3213.57843.32382.59493", ILVersionInfo(3213us,57843us,32382us,59493us) (sprintf "%d.%d.%d.%d" max max max max), ILVersionInfo(max,max,max,max) ] @@ -70,10 +72,10 @@ module ProductVersionTest = let invalidValues () = [ "1.2.3.4", ILVersionInfo(1us,2us,3us,4us) - "1.2.3.4a", ILVersionInfo(1us,2us,3us,0us) - "1.2.c3.4", ILVersionInfo(1us,2us,0us,0us) - "1.2-d.3.4", ILVersionInfo(1us,0us,0us,0us) - "1dd.2.3.4", ILVersionInfo(0us,0us,0us,0us) + "1.2.3.4a", ILVersionInfo(1us,2us,3us,4us) + "1.2.c3.4", ILVersionInfo(1us,2us,0us,4us) + "1.2-d.3.4", ILVersionInfo(1us,0us,3us,4us) + "1dd.2.3.4", ILVersionInfo(0us,2us,3us,4us) "1dd.2da.d3hj.dd4ds", ILVersionInfo(0us,0us,0us,0us) "1.5.6.7.dasd", ILVersionInfo(1us,5us,6us,7us) "9.3", ILVersionInfo(9us,3us,0us,0us) @@ -83,5 +85,5 @@ module ProductVersionTest = [] let ``should zero starting from first invalid version part`` () = - for (v, expected) in invalidValues() do + for (v, expected) in invalidValues() do v |> productVersionToILVersionInfo |> Assert.areEqual expected diff --git a/tests/fsharp/tests.fs b/tests/fsharp/tests.fs index 94c48a17bb6..f382963b765 100644 --- a/tests/fsharp/tests.fs +++ b/tests/fsharp/tests.fs @@ -2835,7 +2835,7 @@ open System.Reflection fv.ProductVersion |> Assert.areEqual "45.2048.main1.2-hotfix (upgrade Second Chance security)" (fv.ProductMajorPart, fv.ProductMinorPart, fv.ProductBuildPart, fv.ProductPrivatePart) - |> Assert.areEqual (45,2048,0,0) + |> Assert.areEqual (45, 2048, 0, 2) []