Skip to content

Lang version 6.0 -> 7.0 value restriction regression. #16007

@vzarytovskii

Description

@vzarytovskii

Consider the following code:

type T() = class end
let dosmth (a: T) = System.Console.WriteLine a
let inline NEW () = (^a : (new : unit -> ^a) ())
let x = NEW ()
dosmth x

Typechecks without issues with --langversion:6.0:

> type T() = class end
- let dosmth (a: T) = System.Console.WriteLine a
- let inline NEW () = (^a : (new : unit -> ^a) ())
- let x = NEW ()
- dosmth x;;
FSI_0002+T
type T =
  new: unit -> T
val dosmth: a: T -> unit
val inline NEW: unit -> ^a when ^a: (``.ctor`` : ^a)
val x: T
val it: unit = ()

>

Fails with --langversion:7.0 and higher:

> type T() = class end
- let dosmth (a: T) = System.Console.WriteLine a
- let inline NEW () = (^a : (new : unit -> ^a) ())
- let x = NEW ()
- dosmth x;;

  let x = NEW ()
  ----^

stdin(4,5): error FS0030: Value restriction. The value 'x' has been inferred to have generic type
    val x: '_a when '_a: (``.ctor`` : '_a) and '_a :> T
Either define 'x' as a simple data term, make it a function with explicit arguments or, if you do not intend for it to be generic, add a type annotation.

Looking through the features list for 7.0 it's probably regressed in one of the following:

LanguageFeature.InterfacesWithAbstractStaticMembers
LanguageFeature.SelfTypeConstraints

Metadata

Metadata

Assignees

No one assigned

    Labels

    AI-thinks-issue-fixedArea-Compiler-CheckingType checking, attributes and all aspects of logic checkingArea-Compiler-SRTPbugs in SRTP inference, resolution, witness passing, code genBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.Regression

    Type

    No fields configured for Bug.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions