Skip to content

Internal error FS0073 "Undefined or unsolved type variable" with nested inline SRTP and multiple overloads #19709

Description

@gusty

When an inline SRTP function dispatches through a type with multiple overloads where a method type parameter only appears in a "don't care" wildcard position (e.g. _ in App<LA, _>), the compiler crashes with:

error FS0073: internal error: Undefined or unsolved type variable: '?NNNNN'

This occurs during IL code generation when the optimizer's compulsory inlining phase resolves trait calls via CodegenWitnessExprForTraitConstraint. The bug requires two or more overloads on the dispatch type. A single overload compiles fine.

Repro steps

type App<'F, 'a> = | App of 'F * 'a

type LA = LA
type LB = LB

type D =
    static member inline Pur(_witness: App<LA, _>, x: 'a) : App<LA, 'a> = App(LA, x)
    static member inline Pur(_witness: App<LB, _>, x: 'a) : App<LB, list<'a>> = App(LB, [x])

let inline pur_impl (_mthd: ^M, output: ^F, x: 'a) : ^F
    when (^M or ^F) : (static member Pur : ^F * 'a -> ^F) =
    ((^M or ^F) : (static member Pur : ^F * 'a -> ^F) (output, x))

let inline pur (x: 'a) : ^F =
    pur_impl (Unchecked.defaultof<D>, Unchecked.defaultof< ^F>, x)

let result : App<LA, int> = pur 1

Removing either Pur overload makes it compile. The _ wildcard in App<LA, _> is key. It introduces an anonymous type parameter that never gets solved.

Expected behavior

The code should compile and run correctly.

Actual behavior

error FS0073: internal error: Undefined or unsolved type variable: '?31223'

Known workarounds

Remove one of the overloads, or avoid wildcard _ in positions that introduce method type parameters.

Related information

Not specific to any .NET version. Reproducilble in F# Interactive version 15.2.202.0 for F# 10.0

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions