Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FS0073: internal error: Undefined or unsolved type variable when using records with generic type variables and overloaded operators in inline function #9416

Closed
idars opened this issue Jun 9, 2020 · 6 comments
Labels
Area-FSI Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Milestone

Comments

@idars
Copy link

idars commented Jun 9, 2020

When defining a set of generic Vector types, I came across this error after adding an inline function that internally uses an overloaded operator (e.g. op_Addition as in the example below) that take a vector and a constant ('T).

Repro steps

  1. Run the following code in Visual Studio (F# Interactive):
type Vector<'T> =
    { X: 'T
      Y: 'T }
    static member inline (+) (u, a) =
        { X = u.X + a
          Y = u.Y + a }

module Vector =
    let inline add (vector: Vector<'T>) amount =
        vector + amount

Expected behavior

Should presumably not throw an internal error.

Actual behavior

F# encounters an internal error:

> error FS0073: internal error: Undefined or unsolved type variable: ^_?16934

Known workarounds

Any of the following steps prevent the internal error from occurring:

  • Avoiding the overloaded operator
  • Using a unary operator instead of a binary operator
  • Removing the inline function
  • Constraining the type variable of amount
  • Not using a generic type variable for Vector

Related information

  • Operating system - Windows 10
  • F# 4.7.2
  • .NET Runtime kind - .NET Core 3.1
  • Editing Tools - Visual Studio 2019 16.5.3

Possibly related issue: #6648

@idars idars changed the title FS0073: internal error: Undefined or unsolved type variable when using generic type variables in records with overloaded operators in inline function FS0073: internal error: Undefined or unsolved type variable when using records with generic type variables and overloaded operators in inline function Jun 9, 2020
@cartermp
Copy link
Contributor

cartermp commented Jun 9, 2020

Worth noting that a console app targeting .NET Core does not exhibit this:

image

@cartermp cartermp added this to the Backlog milestone Jun 9, 2020
@cartermp
Copy link
Contributor

cartermp commented Jun 9, 2020

Confirmed with dotnet fsi as well - there's some weird inconsistency with FSI and compiling as an app going on here

@gusty
Copy link
Contributor

gusty commented Jul 6, 2020

@cartermp I can confirm that the fix @dsyme did while testing F#+ for FS-1043 solves this issue.

Running the sample from an fsi compiled with the feature/ext branch without the language switch compiles fine:

Microsoft (R) F# Interactive version 10.10.0.0 for F# 4.7
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

>
- type Vector<'T> =
-     { X: 'T
-       Y: 'T }
-     static member inline (+) (u, a) =
-         { X = u.X + a
-           Y = u.Y + a }
-
- module Vector =
-     let inline add (vector: Vector<'T>) amount =
-         vector + amount
- ;;
type Vector<'T> =
  { X: 'T
    Y: 'T }
  with
    static member
      ( + ) : u:Vector< ^a> * a: ^b -> Vector< ^c>
                when ( ^a or  ^b) : (static member ( + ) :  ^a *  ^b ->  ^c)
  end
module Vector = begin
  val inline add :
    vector:Vector<'T> -> amount: ^a ->  ^b
      when (Vector<'T> or  ^a) : (static member ( + ) : Vector<'T> *  ^a ->
                                                           ^b)
end

Here's the fix #6805 (comment) I mean, the commits before my comment.

@dsyme
Copy link
Contributor

dsyme commented Sep 1, 2020

I've recorded this in #9416 to investiaget in the context of that branch work

@dsyme dsyme added the Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. label Sep 1, 2020
@moinessim
Copy link

Related? #12761

@vzarytovskii
Copy link
Member

Not reproducing for me in latest main:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-FSI Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Projects
Archived in project
Development

No branches or pull requests

6 participants