Skip to content

Error FS0073 internal error: recursive class hierarchy #11239

Open

Description

@BentTranberg

"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

Activity

  1. cartermp commented on Mar 15, 2021

    @cartermp
    Contributor

    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:

    if ndeep > 100 then error(InternalError("recursive class hierarchy (detected in TypeDefinitelySubsumesTypeNoCoercion), ty1 = " + (DebugPrint.showType ty1), m))

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

  2. added this to the Backlog milestone on Apr 12, 2021
  3. added
    Impact-Medium
    on Jul 14, 2021
  4. added
    Area-Diagnostics
    and removed on Mar 31, 2022
  5. dsyme commented on Mar 31, 2022

    @dsyme
    Contributor

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-DiagnosticsBugImpact-Medium

    Type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions