dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.94k stars 788 forks source link

FS2014 when using tupled args #6379

Open Happypig375 opened 5 years ago

Happypig375 commented 5 years ago

Repro

module Thing
let error =
    let f _ _ _ (stateA, resultA) (stateB, resultB) _ =
        if stateA && stateB then resultA else resultB
    f () () () (true, ()) (true, ()) ()

Zip file with the repro case: FS2014.zip

Expected behavior

Compiles without problem.

Actual behavior

Severity    Code    Description Project File    Line    Suppression State
Error   FS2014  A problem occurred writing the binary 'C:\Users\Admin\source\repos\FS2014\FS2014\obj\Debug\netcoreapp2.1\FS2014.dll': Error in pass2 for type Thing, error: Error in pass2 for type f@3TTTTTD, error: duplicate entry 'tupledArg' in field table    FS2014  C:\Users\Admin\source\repos\FS2014\FS2014\FSC   1   Active

Known workarounds

Modify f, e.g. removing arguments, replacing function body

Related information Microsoft Visual Studio Community 2017 Version 15.9.9 VisualStudio.15.Release/15.9.9+28307.518 Microsoft .NET Framework Version 4.7.03056 Installed Version: Community Visual C++ 2017 00369-60000-00001-AA735 Microsoft Visual C++ 2017 Application Insights Tools for Visual Studio Package 8.14.20131.1 Application Insights Tools for Visual Studio ASP.NET and Web Tools 2017 15.9.04012.0 ASP.NET and Web Tools 2017 ASP.NET Core Razor Language Services 15.8.31590 Provides languages services for ASP.NET Core Razor. ASP.NET Web Frameworks and Tools 2017 5.2.60913.0 For additional information, visit https://www.asp.net/ Azure App Service Tools v3.0.0 15.9.03024.0 Azure App Service Tools v3.0.0 C# Tools 2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools. Dotfuscator Community Edition 5.36.0.7050-e77ce80a6 PreEmptive Protection - Dotfuscator CE Extensibility Message Bus 1.1.49 (remotes/origin/d15-8@ee674f3) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration. GitHub.VisualStudio 2.8.1.7307 A Visual Studio Extension that brings the GitHub Flow into Visual Studio. JavaScript Language Service 2.0 JavaScript Language Service JavaScript Project System 2.0 JavaScript Project System JavaScript UWP Project System 2.0 JavaScript UWP Project System Microsoft Continuous Delivery Tools for Visual Studio 0.4 Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE. Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines Microsoft Library Manager 1.0 Install client-side libraries easily to any web project Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers Microsoft Visual C++ Wizards 1.0 Microsoft Visual C++ Wizards Microsoft Visual Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container. Microsoft Visual Studio VC Package 1.0 Microsoft Visual Studio VC Package MLGen Package Extension 1.0 MLGen Package Visual Studio Extension Detailed Info Mono Debugging for Visual Studio 4.13.12-pre (9bc9548) Support for debugging Mono processes with Visual Studio. NuGet Package Manager 4.6.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/. ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info ResourcePackage Extension 1.0 ResourcePackage Visual Studio Extension Detailed Info ResourcePackage Extension 1.0 ResourcePackage Visual Studio Extension Detailed Info SQL Server Data Tools 15.1.61903.01040 Microsoft SQL Server Data Tools Syntax Visualizer 1.0 An extension for visualizing Roslyn SyntaxTrees. TypeScript Tools 15.9.20918.2001 TypeScript Tools for Microsoft Visual Studio Visual Basic Tools 2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Visual F# Tools 10.2 for F# 4.5 15.8.0.0. Commit Hash: 6e26c5bacc8c4201e962f5bdde0a177f82f88691. Microsoft Visual F# Tools 10.2 for F# 4.5 Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio Visual Studio Tools for Containers 1.0 Visual Studio Tools for Containers Visual Studio Tools for Unity 3.9.0.3 Visual Studio Tools for Unity Visual Studio Tools for Universal Windows Apps 15.0.28307.489 The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit. VisualStudio.Mac 1.0 Mac Extension for Visual Studio Xamarin 4.12.3.80 (d15-9@914127c74) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android. Xamarin Designer 4.16.13 (45a16efd4) Visual Studio extension to enable Xamarin Designer tools in Visual Studio. Xamarin Templates 1.1.128 (6f5ebb2) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms. Xamarin.Android SDK 9.1.7.0 (HEAD/ba9da7a76) Xamarin.Android Reference Assemblies and MSBuild support. Xamarin.iOS and Xamarin.Mac SDK 12.2.1.15 (d60abd1) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
TIHan commented 5 years ago

Can confirm, happens when compiling as Debug in VS. Release seems to work though.

auslavs commented 4 years ago

I believe have a similar error

FSC : error FS2014: A problem occurred writing the binary 'C:\Users\slavinr\Source\Repos\errorFS2014\ConsoleApp\obj\Debug\netcoreapp3.1\ConsoleApp.dll': Error in pass3 for type Program, error: Error in pass3 for type MyClass, error: Error in GetMethodRefAsMethodDefIdx for mref = ("Example-IMessageReader`1-TryParseMessage", "MyClass"), error: Exception of type 'FSharp.Compiler.AbstractIL.ILBinaryWriter+MethodDefNotFound' was thrown. [C:\Users\slavinr\Source\Repos\errorFS2014\ConsoleApp\ConsoleApp.fsproj]

when trying to compiler the following code

type BaseMessage = 
  struct
    val Payload : ReadOnlySequence<byte>
    new (payload: ReadOnlySequence<byte>) = { Payload = payload }
  end

type MyClass() =

  interface IMessageReader<BaseMessage> with
      member this.TryParseMessage(input: inref<ReadOnlySequence<byte>>, consumed: byref<SequencePosition>, examined: byref<SequencePosition>, message: byref<BaseMessage>): bool = 
          failwith "Not Implemented" 

The interface is defined in a seperate C# project

Repro here: https://github.com/auslavs/errorFS2014

cartermp commented 4 years ago

@auslavs which VS version are you using? Does this also reproduce in release?

auslavs commented 4 years ago

@cartermp yep, same thing for release.

VS Details below, I have repro'd in VS, VsCode and using dotnet build.

Microsoft Visual Studio Professional 2019 Version 16.4.2 VisualStudio.16.Release/16.4.2+29613.14 Microsoft .NET Framework Version 4.8.03761 Installed Version: Professional ADL Tools Service Provider 1.0 This package contains services used by Data Lake tools ASP.NET and Web Tools 2019 16.4.457.38025 ASP.NET and Web Tools 2019 ASP.NET Web Frameworks and Tools 2019 16.4.457.38025 For additional information, visit https://www.asp.net/ Azure App Service Tools v3.0.0 16.4.457.38025 Azure App Service Tools v3.0.0 Azure Data Lake Node 1.0 This package contains the Data Lake integration nodes for Server Explorer. Azure Data Lake Tools for Visual Studio 2.4.1000.0 Microsoft Azure Data Lake Tools for Visual Studio Azure Functions and Web Jobs Tools 16.4.457.38025 Azure Functions and Web Jobs Tools Azure Stream Analytics Tools for Visual Studio 2.4.1000.0 Microsoft Azure Stream Analytics Tools for Visual Studio C# Tools 3.4.1-beta4-19610-02+c4e5d138903b899477649a17f197abd2bcb22f9e C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools. Fabric.DiagnosticEvents 1.0 Fabric Diagnostic Events IntelliCode Extension 1.0 IntelliCode Visual Studio Extension Detailed Info Microsoft Azure HDInsight Azure Node 2.4.1000.0 HDInsight Node under Azure Node Microsoft Azure Hive Query Language Service 2.4.1000.0 Language service for Hive query Microsoft Azure Service Fabric Tools for Visual Studio 16.0 Microsoft Azure Service Fabric Tools for Visual Studio Microsoft Azure Stream Analytics Language Service 2.4.1000.0 Language service for Azure Stream Analytics Microsoft Azure Stream Analytics Node 1.0 Azure Stream Analytics Node under Azure Node Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.21016.1 Microsoft Continuous Delivery Tools for Visual Studio 0.4 Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE. Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines Microsoft Library Manager 2.0.87+gbb515bf382 Install client-side libraries easily to any web project Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers Microsoft Visual Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container. NuGet Package Manager 5.4.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/ ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info SQL Server Data Tools 16.0.61912.09160 Microsoft SQL Server Data Tools ToolWindowHostedEditor 1.0 Hosting json editor into a tool window TypeScript Tools 16.0.11031.2001 TypeScript Tools for Microsoft Visual Studio Visual Basic Tools 3.4.1-beta4-19610-02+c4e5d138903b899477649a17f197abd2bcb22f9e Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Visual F# Tools 10.4 for F# 4.6 16.4.0-beta.19556.5+e7597deb7042710a7142bdccabd6f92b0840d354 Microsoft Visual F# Tools 10.4 for F# 4.6 Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio Visual Studio Container Tools Extensions (Preview) 1.0 View, manage, and diagnose containers within Visual Studio. Visual Studio Tools for Containers 1.0 Visual Studio Tools for Containers Visual Studio Tools for Kubernetes 1.0 Visual Studio Tools for Kubernetes WiX Toolset Visual Studio Extension 1.0.0.4 WiX Toolset Visual Studio Extension version 1.0.0.4 Copyright (c) .NET Foundation and contributors. All rights reserved.
auslavs commented 4 years ago

It appears as though my issue was with the inref. The C# Interface uses a in modifier on the first parameter, removing this requirement also removes the compiler error.

abelbraaksma commented 4 years ago

But that would suggest that implementing an interface with inref is not possible. Maybe that's by design, but if so, it would be nice to have the error at an earlier stage than when writing the binary.

auslavs commented 4 years ago

@abelbraaksma I can't seem to find any info on whether or not it is by design. Th byrefs seem to work fine though.

I share you sentiment that it would be good to know about this earlier if it was by design

TIHan commented 4 years ago

@auslavs This is a compiler bug and should compile and run successfully. I will spend time on resolving it this week.

TIHan commented 4 years ago

So, @auslavs , the error you have is similar to the one reported here, but the cause is very different. I have a fix for your issue: https://github.com/dotnet/fsharp/pull/8287

Regarding this issue, I will look into; it's been almost a year.

auslavs commented 4 years ago

@TIHan Thank you very much!

RealmPlume commented 2 years ago

I know how it is caused, The following user code can avoid this bug:

module Thing =

   let error() =
      let f _ _ _ ((stateA, resultA)) ((stateB, resultB)) () =
         if stateA && stateB then 
            resultA 
         else 
            resultB
      f () () () (true, ()) (true, ()) ()

I think it puts all arguments in a tuple when it starts to compile that code. When there are more than 7 elements, the following arguments are placed in the sub-tuple of rest, so two tupledArg0 are generated.