Skip to content

FCS crash with ConstraintSolverMissingConstraint on valid F# file #19118

@Smaug123

Description

@Smaug123

FCS crashes, incorrectly claiming (I think) that the 'appEvent generic is required to have comparison, when accessing the ImmediateSubexpressions in this small valid F# library.

namespace Foo

type Bar<'appEvent> =
    | Wibble of 'appEvent

I saw this in the wild when trying to run an Ionide F# analyzer against one of my own projects (I originally raised that bug as ionide/FSharp.Analyzers.SDK#276 ).

Repro steps

// TestThing.fs
namespace WoofWare.Zoomies.Test

open System
open System.IO
open FSharp.Compiler.CodeAnalysis
open FSharp.Compiler.Symbols
open FSharp.Compiler.Text
open FsUnitTyped
open NUnit.Framework

[<TestFixture>]
module TestWorldFreezer =

    [<Test>]
    let ``demo of bug`` () = task {
        let s = """namespace Foo

type Bar<'appEvent> =
    | Wibble of 'appEvent"""

        let outFile = Path.Combine (Path.GetTempPath (), Guid.NewGuid().ToString () + ".fsx")
        try
            File.WriteAllText (outFile, s)

            let checker = FSharpChecker.Create (keepAssemblyContents=true)
            let! options, _diags = checker.GetProjectOptionsFromScript (outFile, SourceText.ofString s)

            let! t, u = checker.ParseAndCheckFileInProject (outFile, 0, SourceText.ofString s, options)
            t.Diagnostics.Length |> shouldEqual 0
            let v =
                match u with
                | FSharpCheckFileAnswer.Succeeded x -> x
                | FSharpCheckFileAnswer.Aborted -> failwith "bad"

            let decl =
                let rec go (decl : FSharpImplementationFileDeclaration) =
                    match decl with
                    | FSharpImplementationFileDeclaration.Entity (_, declarations) ->
                        declarations |> List.iter go
                    | FSharpImplementationFileDeclaration.MemberOrFunctionOrValue (_, _, e) ->
                        e.ImmediateSubExpressions
                        |> ignore
                    | _ -> failwith "no"

                go (v.ImplementationFile.Value.Declarations |> List.exactlyOne)

            return ()
        finally
            try
                File.Delete outFile
            with | _ -> ()
    }
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
    <IsPackable>false</IsPackable>
    <OutputType>Exe</OutputType>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="TestThing.fs" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="FsCheck" Version="3.3.1" />
    <PackageReference Include="FsUnit" Version="7.1.1"/>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1"/>
    <PackageReference Include="FSharp.Compiler.Service" Version="[43.10.100]" />
    <PackageReference Include="FSharp.Core" Version="10.0.100" />
    <PackageReference Include="NUnit" Version="4.3.2" />
    <PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
  </ItemGroup>
</Project>

Run the test.

Expected behavior

The test passes, having successfully visited each node of the TAST.

Actual behavior

FSharp.Compiler.DiagnosticsLogger+ReportedError : The exception has been reported. This internal exception should now be caught at an error recovery point on the stack. Original message: ConstraintSolverMissingConstraint
  ({ includeStaticParametersInTypeNames = false
     openTopPathsSorted =
      Internal.Utilities.Library.InterruptibleLazy`1[Microsoft.FSharp.Collections.FSharpList`1[Microsoft.FSharp.Collections.FSharpList`1[System.String]]]
     openTopPathsRaw = []
     shortTypeNames = false
     suppressNestedTypes = false
     maxMembers = None
     showObsoleteMembers = false
     showHiddenMembers = false
     showTyparBinding = false
     showInferenceTyparAnnotations = false
     suppressInlineKeyword = true
     suppressMutableKeyword = false
     showMemberContainers = false
     shortConstraints = false
     useColonForReturnType = false
     showAttributes = false
     showCsharpCodeAnalysisAttributes = false
     showOverrides = true
     showStaticallyResolvedTyparAnnotations = true
     showNullnessAnnotations = None
     abbreviateAdditionalConstraints = false
     showTyparDefaultConstraints = false
     showDocumentation = false
     shrinkOverloads = true
     printVerboseSignatures = false
     escapeKeywordNames = false
     g = <TcGlobals>
     contextAccessibility = public
     generatedValueLayout = <fun:Empty@3244>
     genericParameterStyle = Implicit }, appEvent,
   SupportsComparison (4,6--4,12), (4,6--4,12), (4,6--4,12)))
   at FSharp.Compiler.DiagnosticsLogger.DiagnosticsLoggerExtensions.DiagnosticsLogger.Error[T](DiagnosticsLogger x, Exception exn) in D:\a\_work\1\s\src\fsharp\src\Compiler\Facilities\DiagnosticsLogger.fs:line 475
   at FSharp.Compiler.DiagnosticsLogger.CommitOperationResult[T](OperationResult`1 res) in D:\a\_work\1\s\src\fsharp\src\Compiler\Facilities\DiagnosticsLogger.fs:line 664
   at FSharp.Compiler.Symbols.FSharpExprConvert.GetWitnessArgs(SymbolEnv cenv, ExprTranslationEnv env, ValRef vref, Range m, FSharpList`1 tps, FSharpList`1 tyargs) in D:\a\_work\1\s\src\fsharp\src\Compiler\Symbols\Exprs.fs:line 519
   at FSharp.Compiler.Symbols.FSharpExprConvert.ConvModuleValueOrMemberUseLinear(SymbolEnv cenv, ExprTranslationEnv env, Expr expr, ValRef vref, ValUseFlag vFlags, FSharpList`1 tyargs, FSharpList`1 curriedArgs, FSharpFunc`2 contF) in D:\a\_work\1\s\src\fsharp\src\Compiler\Symbols\Exprs.fs:line 505
   at FSharp.Compiler.Symbols.FSharpExprConvert.ConvExprOnDemand@1339.Invoke(Unit unitVar0) in D:\a\_work\1\s\src\fsharp\src\Compiler\Symbols\Exprs.fs:line 1339
   at FSharp.Compiler.Symbols.FSharpExpr.get_E() in D:\a\_work\1\s\src\fsharp\src\Compiler\Symbols\Exprs.fs:line 153
   at FSharp.Compiler.Symbols.FSharpExpr.get_ImmediateSubExpressions() in D:\a\_work\1\s\src\fsharp\src\Compiler\Symbols\Exprs.fs:line 157

Known workarounds

none

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions