fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

Error FS0073 internal error: recursive class hierarchy

Open BentTranberg opened this issue 4 years ago • 2 comments

"internal error" - doesn't that mean the compiler error is actually a bug in the compiler?

Source that demonstrates the error.

open FSharpPlus

let test1 () =
    (fun x y -> x, y) |> memoizeN // OK

let test2 () =
    memoizeN (fun x y -> x, y) // Error
    // Error FS0073 internal error: recursive class hierarchy (detected in TypeFeasiblySubsumesType), ty1 = MemoizeN
    // Error FS0002 This function takes too many arguments, or is used in a context where a function is not expected

let test3 () =
    let f = (fun x y -> x, y)
    memoizeN f // OK

[<EntryPoint>]
let main argv =
    let f1 = test1 ()
    let f2 = test2 ()
    let f3 = test3 ()
    0

Repro steps

  1. Create an F# console project in VS 2019 v 16.9.1, TargetFramework net5.0
  2. Modify the source in Program.fs as shown above.
  3. Compile.

Expected behavior

No compiler error.

Known workarounds

Shown in test1 and test3 in the source above.

Related information

I have looked through similar issues in this repo without finding anything that seems relevant, and also can't find anything else when searching for "recursive class hierarchy". So I guess this is of interest.

I found this in a question on StackOverflow. This is the link : https://stackoverflow.com/questions/66622657/f-has-a-discrepancy-between-func-lambda-and-lambda-func

BentTranberg avatar Mar 15 '21 12:03 BentTranberg

So this isn't necessarily a bug, since there are several places where we hold an invariant and emit this error when it's not met:

https://github.com/dotnet/fsharp/blob/6b1af129b798d0b3b7c296b27e8c2a5ad4f1dad8/src/fsharp/TypeRelations.fs#L26

The question is if this invariant makes sense under this context or not.

cartermp avatar Mar 15 '21 15:03 cartermp

This is by design - a use of SRTP has caused an infinite regression in type inference (generally this is not possible in F#, but with non-recommended uses of SRTP like in FSharpPlus it can happen).

The use of an InternalError diagnostic can be much improved

dsyme avatar Mar 31 '22 05:03 dsyme