New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected behavior with struct multicase unions #1678
Comments
You also get the same in the case with something like this
I've not taken a look at the implementation of struct multi case unions, but I'm guessing that a unique constructor is built per signature of each case? That would explain why it fails for cases with duplicate signatures ? |
I just installed F# support for the latest VS2017 RC and hit this issue. It fails every time two or more cases have the same type. Inspecting the IL emitted for struct unions I see a private constructor for each case. I think the easiest fix would be having a single constructor, with a parameter for every field. |
@mistiara Yes, we need to document this limitation, it is a bug in F# 4.1. We will fix it. |
Is there any way to tell if it's in the fsharp/fsharp yet? |
@et1975 I believe fsharp/fsharp is dead. Build the compiler from this repo. |
No, not dead - just aligned. TBH it will never be "dead" because its existence forms part of the mission statement of the FSSF. Right now, all the Mono distributions, FSharp.Compiler.Tools and FSharp.Compiler.Service packages are still packaged via integrations and tagging in that repo and/or fsharp/FSharp.Compiler.Service and other downstream packaging repos. The details are in https://github.com/fsharp/fsharp/blob/master/README.md So fsharp/fsharp is really just a downstream packaging repo. Unless absolutely critical (e.g. in preparing Mono releases) all contributions should go via this repo. |
Is there any way to tell if this (or any other fix) has been released, in MS and/or Open distributions? |
@et1975 I'm not sure if there's an official way to tell, but I confirm this particular fix is in the latest f# compiler nuget package. |
I just checked it with .NET Core 2.0 preview2 SDK (2.0.0-preview2-006497) and still hit the "duplicate entry '.ctor' in method table" issue with this example: [<Struct>]
type DU = Case1 | Case2 |
I can confirm this with Preview 3 as well: @KevinRansom does the compiler in the .NET Core SDK not contain the fix in #2811? |
@cartermp yes, that code is in both master and vs2017-rtm. It is in both the desktop and coreclr builds. |
@et1975 Everything that was in master before 7/27/2017 is in the release branch for VS2017.3. Merge PR: 4a312d3 The latest dotnet/cli compiler and nuget released Microsoft.FSharp.Compiler was built including those changes. The VS2017.3 rtm branch contain cherry-picks of the most important recent changes to master. We don't have a great process for identifying when something goes from master to vs2017-rtm, that is usually controlled by the VS release cadence and the level of risk that can be allowed against the VS release. There is also the bar for the dotnet-cli to take into account, although we release to that out of VS2017-RTM via the nuget Microsoft.FSharp.Compiler.nuget package. I'm sorry it's so difficult to figure out, releasing code to millions of users is a black-art and I am but a cog in the machine. The rule of thumb I use is this --- So far we have included code in VS2017, VS2017.2 and VS2017.3. After a release has occurred, master will be merged into vs2017-rtm and relevant vs2017-rtm changes will be merged back into master. All of the above is dependent on approvals from the VS release team and their goals for each release. |
Hmmmm. Then it appears that @dsyme's PR didn't fix this duplicate ctor bug. |
Does that work cross platform? I tested with the latest build of SDK 2.0 on macOS and repro'd. |
Should work fine cross platform. |
Works on MAC-OS with the latest bits. You need to use release/2.0.0 branch or rel/1.1.0 for attest bits. master is a bit whacky on dotnet/cli
|
@KevinRansom The example you posted (struct du with different unique type for each case) works fine with .NET Core preview2 (2.0.0-preview2-006497) running on Ubuntu 16.04. However it seems that the struct du the typeless/parameterless cases are not handled properly in the preview2 version of the sdk. The compiler for this example at least provide an error why the struct du is not compilable (current struct du limitation): open System
[<Struct>]
type DU =
| Case1 of int
| Case2 of int
[<EntryPoint>]
let main argv =
printfn "Hello World from F#!"
0 // return an integer exit code
However for the following case, the compiler does not give any information why the compilation fails (current struct du limitations): open System
[<Struct>]
type DU =
| Case1
| Case2
[<EntryPoint>]
let main argv =
printfn "Hello World from F#!"
0 // return an integer exit code
|
That's what I'm using. On rel/2.0.0: [<Struct>]
type Foo = Bar | Baz
[<EntryPoint>]
let main argv =
printfn "Hello World from F#!"
0 // return an integer exit code Fails:
|
@cartermp I tried
on master and it works correctly for me |
The latest F# 4.1 compiler fails to compile either of the following code programs on .NET Core:
With this error:
FSC : error FS2014: A problem occurred writing the binary '/Users/phillip/scratch/test/obj/Debug/netcoreapp2.0/test.dll': Error in pass2 for type Program, error: Error in pass2 for type Foo, error: duplicate entry '.ctor' in method table [/Users/phillip/scratch/test/test.fsproj]
This is one rel/2.0.0 of the .NET CLI.
--- Old Issue ---
In VS "15" Preview 5, if you have the following:
The following error occurs:
If I remove the
Square
case , or change it to be of typeint
, it compiles.The text was updated successfully, but these errors were encountered: