Skip to content

error FS0192 : internal error : unexpected non-generation of witness with FSharp.Core 5.0 #10472

Closed

Description

@marklam

Code that previously compiled no longer builds with F# 5.0 and FSharp.Core 5.0

Perform a debug build of a .net5 class library with the code:

module Adapter =
    let inline clamp16 v = uint16 (max 0. (min 65535. v))
    let inline clamp8  v = uint8  (max 0. (min   255. v))

    type Clampage =
        static member inline FromFloat (_ : byte,   _ : Clampage) = fun (x : float) -> clamp8  x
        static member inline FromFloat (_ : uint16, _ : Clampage) = fun (x : float) -> clamp16 x

        static member inline Invoke (x: float) : 'Num =
            let inline call2 (a: ^a, b: ^b) = ((^a or ^b) : (static member FromFloat : _*_ -> _) (b, a))
            let inline call (a: 'a) = fun (x: 'x) -> call2 (a, Unchecked.defaultof<'r>) x : 'r
            call Unchecked.defaultof<Clampage> x

Expected behavior

Code compiles (which it does in release)

Actual behavior

error FS0192 : internal error : unexpected non-generation of witness

Known workarounds

Set /langversion:4:7 in build options or project file <OtherFlags>

Related information

  • Windows 10
  • .net 5
  • Visual Studio 2019 16.8.1

Sample project:
Thing.zip

Activity

  1. added
    Impact-Medium
    on Nov 16, 2020
  2. TIHan commented on Nov 16, 2020

    @TIHan
    Contributor

    // cc @dsyme

  3. modified the milestones: Backlog, 16.9 on Nov 16, 2020
  4. dsyme commented on Nov 16, 2020

    @dsyme
    Contributor

    @marklam Note that setting /langversion4:7 allows a workaround

  5. marklam commented on Nov 16, 2020

    @marklam
    Author

    @dsyme Thanks.

  6. TysonMN commented on Nov 23, 2020

    @TysonMN

    Known workarounds

    Set /langversion:4:7 in build options or project file <OtherFlags>

    In the case of project file <OtherFlags>, the specific notation for the workaround is --langversion:4.7. The whole line is

    <OtherFlags>--langversion:4.7</OtherFlags>
  7. self-assigned this
    on Dec 1, 2020
  8. modified the milestones: 16.9, Backlog on Dec 1, 2020
  9. smoothdeveloper commented on Dec 26, 2020

    @smoothdeveloper
    Contributor

    Also hit on https://github.com/smoothdeveloper/zcore-midi-fs it comes with a long stack trace of the compiler eventually reaching this instance of the message:

    fsharp/src/fsharp/IlxGen.fs

    Lines 3137 to 3146 in b23b2a0

    and GenWitnessArgFromWitnessInfo cenv cgbuf eenv m witnessInfo =
    let g = cenv.g
    let storage = TryStorageForWitness g eenv witnessInfo
    match storage with
    | None ->
    System.Diagnostics.Debug.Assert(false, "expected storage for witness")
    failwith "unexpected non-generation of witness "
    | Some storage ->
    let ty = GenWitnessTy g witnessInfo
    GenGetStorageAndSequel cenv cgbuf eenv m (ty, GenType cenv.amap m eenv.tyenv ty) storage None

  10. gusty commented on Jan 13, 2021

    @gusty
    Contributor

    I'm also facing this error in a production project which I can't share.

    Setting lang to 4.7 is annoying as we want to take advantage of new features.

  11. cartermp commented on Jan 13, 2021

    @cartermp
    Contributor

    Just for posterity you don't need OtherFlags and I would recomment using <LangVersion> property instead.

    @dsyme would you be able to take a look here?

  12. modified the milestones: Backlog, 16.10 on Feb 6, 2021
  13. gusty commented on Mar 30, 2021

    @gusty
    Contributor

    @dsyme What's the status on this? Why Backlog?

    I was hoping this issue to get prioritized as it's a regression, and it's preventing us to move to our new libraries which use F# 5.0

    I still really hope you can find a fix soon.

  14. dsyme commented on Apr 1, 2021

    @dsyme
    Contributor

    There's a fix coming in #11349

  15. TysonMN commented on May 27, 2021

    @TysonMN

    FWIW, I have confirmed that this issue is fixed when using Visual Studio 16.10 and FSharp.Core 5.0.1

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

Metadata

Metadata

Assignees

Labels

BugImpact-MediumRegression

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions