You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Lang version 6.0 -> 7.0 value restriction regression. #16007
typeT()=classendletdosmth(a:T)= System.Console.WriteLine a
let inlineNEW()=(^a:(new: unit ->^a)())letx= 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:
I tested this with the current compiler (F# Interactive version 15.2.100.0 for F# 11.0, commit a0cce49, .NET 10.0.5 on Linux):
$ echo '#version;;' | fsi
Microsoft (R) F# Interactive version 15.2.100.0 for F# 11.0
Language Version: 10.0
FSharp.Core: 11.0.0.0
.NET: .NET 10.0.5
The repro code:
typeT()=classendletdosmth(a:T)= System.Console.WriteLine(a.ToString())let inlineNEW()=(^a:(new: unit ->^a)())letx= NEW ()
dosmth x
Results:
LangVersion
Result
8.0
✅ Compiles and runs correctly
9.0
✅ Compiles and runs correctly
10.0 (default)
✅ Compiles and runs correctly
11.0
✅ Compiles and runs correctly
The value restriction error that was regressed in langversion:7.0 is no longer present from F# 8.0 onwards. Note: langversion:6.0 and 7.0 are now out of support in the current SDK, but all supported language versions (8.0+) compile this code without error.
This regression appears to have been fixed in F# 8.
Activity
haraldsteinlechner commentedon Jan 22, 2025
Hi, i think we are hitting this throughout aardvark ui libraries, aardvark-platform/aardvark.media@bc58750#diff-81091dc0e2f6f8037b6c8039cd7d6e765db9cd0927987dc3c7bc7f3719b3c214R112
in our case it is a record construction with SRTP Unpersist involved (see here: https://github.com/krauthaufen/Adaptify/blob/078f083d98cd5660139398670649bc09e1a365bc/src/Adaptify.Core/Attributes.fs#L49)
github-actions commentedon Mar 28, 2026
🤖 This is an automated response from Repo Assist.
I tested this with the current compiler (F# Interactive version 15.2.100.0 for F# 11.0, commit
a0cce49, .NET 10.0.5 on Linux):The repro code:
Results:
8.09.010.0(default)11.0The value restriction error that was regressed in
langversion:7.0is no longer present from F# 8.0 onwards. Note:langversion:6.0and7.0are now out of support in the current SDK, but all supported language versions (8.0+) compile this code without error.This regression appears to have been fixed in F# 8.
Add regression test: #16007, SRTP ctor constraint no longer causes va…
Add regression test: #16007, SRTP ctor constraint no longer causes va…
Syncing release/dev18.6 with VS rel/insiders (#19699)