-
Notifications
You must be signed in to change notification settings - Fork 854
Labels
Area-Compiler-CodeGenIlxGen, ilwrite and things at the backendIlxGen, ilwrite and things at the backendBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.(Internal MS Team use only) Describes an issue with moderate impact on existing code.
Milestone
Description
F# 7.0 compiled program failed to run .
Repro steps
// fail to run in release config
// runtime: .net framework 4.7
// F# version: 7.0 12.0.5.0
// Visual Studio 2022
(*
error message: System.TypeLoadException:
'Method 'Specialize' on type 'memoizeLatestRef@5-1' from
assembly 'FSharpCompilerBugs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
tried to implicitly override a method with weaker type parameter constraints.'
*)
let inline refEquals<'a when 'a : not struct> (a : 'a) (b : 'a) = obj.ReferenceEquals (a, b)
let inline tee f x =
f x
x
let memoizeLatestRef (f: 'a -> 'b) =
let cell = ref None
let f' (x: 'a) =
match !cell with
| Some (x', value) when refEquals x' x -> value
| _ -> f x |> tee (fun y -> cell := Some (x, y))
f'
module BugInReleaseConfig =
let test f x =
printfn "%s" (f x)
let f: string -> string = memoizeLatestRef id
let run () = test f "ok"
[<EntryPoint>]
let main argv =
let culture = System.Globalization.CultureInfo("en")
System.Globalization.CultureInfo.CurrentCulture <- culture
System.Globalization.CultureInfo.CurrentUICulture <- culture
BugInReleaseConfig.run ()
System.Console.ReadLine() |> ignore
0Expected behavior
It should print "ok".
Actual behavior
A System.TypeLoadException was throwed.
Source code
FSharpCompilerBugs.zip
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area-Compiler-CodeGenIlxGen, ilwrite and things at the backendIlxGen, ilwrite and things at the backendBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.(Internal MS Team use only) Describes an issue with moderate impact on existing code.
Type
Projects
Status
New