Fsharp: --langversion parser is culture-dependent

Created on 22 Oct 2019  Â·  5Comments  Â·  Source: dotnet/fsharp

Repro steps

  1. Create a new F# project: dotnet new console -lang F#
  2. Add <LangVersion> to the project:

    <Project Sdk="Microsoft.NET.Sdk">
     <PropertyGroup>
       <OutputType>Exe</OutputType>
       <TargetFramework>netcoreapp3.0</TargetFramework>
       <LangVersion>4.7</LangVersion>
     </PropertyGroup>
     <ItemGroup>
       <Compile Include="Program.fs" />
     </ItemGroup>
    </Project>
    
  3. Now, try to build the project:

    $ dotnet build
    Microsoft (R) Build Engine version 16.3.0+0f4c62fea for .NET Core
    Copyright (C) Microsoft Corporation. All rights reserved.
    
     Restore completed in 26,26 ms for T:\Temp\fsproj\fsproj.fsproj.
    FSC : error FS0246: Unrecognized value '4.7' for --langversion use --langversion:? for complete list [T:\Temp\fsproj\fsproj.fsproj]
    

It seems to be linked with my machine's Russian culture (which uses decimal comma instead of decimal point).

Known workarounds

Use <LangVersion>4,7</LangVersion> (yes, with a comma!) — but please never do that, it's totally not portable

Additional info

It's not a dotnet build issue, the same happens if I directly invoke dotnet fsc.exe:

$ cd "C:\Program Files\dotnet\sdk\3.0.100\FSharp"
$ dotnet fsc.exe --langversion:4.7

error FS0246: Unrecognized value '4.7' for --langversion use --langversion:? for complete list

$ dotnet fsc.exe --langversion:4,7
Microsoft (R) F# Compiler version 10.6.0.0 for F# 4.7
Copyright (c) Microsoft Corporation. All Rights Reserved.

error FS0207: No inputs specified

Related information

$ dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.0.100
 Commit:    04339c3a26

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100\

Host (useful for support):
  Version: 3.0.0
  Commit:  7d57652f33
Area-Compiler bug

Most helpful comment

Notably, the following works, too:

$ dotnet fsc.exe --langversion:4,700000000000000000000000000000000000000001

Because 4,700000000000000000000000000000000000000001 is exactly the same _double_ as 4,7.

I don't think it's a good idea to parse the version numbers as floating point values.

All 5 comments

Notably, the following works, too:

$ dotnet fsc.exe --langversion:4,700000000000000000000000000000000000000001

Because 4,700000000000000000000000000000000000000001 is exactly the same _double_ as 4,7.

I don't think it's a good idea to parse the version numbers as floating point values.

Versions should clearly not be a numeric value. I believe Microsoft adopted Semver, so possible values can include multiple dots and a build string (even though that may not be supported right now by LangVersion, several versions strings used with F# in the past cannot be processed as decimal, so it should be agnostic to that). In other words, this should be a string value and not parsed into a decimal.

BTW, the same issue happens in the Netherlands and Germany, and I'm sure there are others.

This should be easy to resolve, though semver doesn't apply to language versioning.

I assume that you would want to use Version.Parse for this.

As one can think off, this happens also with F# in Visual Studio 2019 (16.3.9) and German Windows. Obviously <LangVersion>4,6</LangVersion> should not be committed to any Github repo - the CI build will fail in all likelihood.

Was this page helpful?
0 / 5 - 0 ratings