Skip to content

error FS0073: internal error: Undefined or unsolved type variable when using records with generic type variables and backgroundTask #12761

@moinessim

Description

@moinessim

Getting internal error when trying to compile generic type that uses backgroundTask expression.

open System.Text.Json

type Dto = {
    DtoValue : string
    Key : string
}

type MyGenericType<'Key,'Value> = {
    Value : 'Value
    Key : 'Key
}

type ProblematicType<'Key, 'Value, 'Dto, 'E>( fromDto : 'Dto -> Result<MyGenericType<'Key,'Value>,'E> ) =
    let myTask = 
        backgroundTask {
            let dto =  """{"DtoValue":"1","Key":"key1"}""" |> JsonSerializer.Deserialize<'Dto>
            return fromDto dto |> printfn "%A"
        }
    member __.ContainsKey = fun (key: 'Key) -> true


type MyType = MyGenericType<string,int>

module MyType =
    let fromDto (dto: Dto)  =
        try
            {
                Value = int dto.DtoValue
                Key = dto.Key
            } 
            |> Ok
        with | e -> Error e


let problem = ProblematicType<string,int,Dto,exn>(MyType.fromDto)

Provide the steps required to reproduce the problem:

  1. Execute above code in FSI or try to compile in console app with dotnet build.

If possible attach a zip file with the repro case. This often makes it easier for others to reproduce.
The zip file should ideally represent the situation just before the call/step that is problematic.

Expected behavior

It should compile and run successfully.

Actual behavior

      backgroundTask {

--------^^^^^^^^^^^^^^

error FS0073: internal error: Undefined or unsolved type variable: 'Key

Known workarounds

Use task instead of backgroundTask expression.

Related information

.NET SDK (reflecting any global.json):
Version: 6.0.100
Commit: 9e8b04bbff

Runtime Environment:
OS Name: Mac OS X
OS Version: 11.5
OS Platform: Darwin
RID: osx.11.0-x64
Base Path: /nix/store/nwyx15pwbkfqxl818q2nhh3cmnmvygik-dotnet-sdk-6.0.100/sdk/6.0.100/

Host (useful for support):
Version: 6.0.0
Commit: 4822e3c3aa

.NET SDKs installed:
6.0.100 [/nix/store/nwyx15pwbkfqxl818q2nhh3cmnmvygik-dotnet-sdk-6.0.100/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.0 [/nix/store/nwyx15pwbkfqxl818q2nhh3cmnmvygik-dotnet-sdk-6.0.100/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.0 [/nix/store/nwyx15pwbkfqxl818q2nhh3cmnmvygik-dotnet-sdk-6.0.100/shared/Microsoft.NETCore.App]

Metadata

Metadata

Assignees

Labels

Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingArea-Compiler-StateMachinesSequence, list, task and other state machine compilationBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions