Created
February 5, 2016 19:18
-
-
Save hafuu/a465449c13511a574af0 to your computer and use it in GitHub Desktop.
InferredFloatRepro.fs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module InferredFloatRepro | |
| open Microsoft.FSharp.Compiler.SourceCodeServices | |
| open System.IO | |
| let inferredFloatFunction x = 0.0 + x | |
| let annotatedFloatFunction (x: float): float = 0.0 | |
| let inferredIntFunction x = 0 + x | |
| type Dummy = Dummy | |
| let loadAssembly () = | |
| let asm = typeof<Dummy>.Assembly | |
| let checker = FSharpChecker.Create() | |
| let base1 = Path.GetTempFileName() | |
| let fileName1 = Path.ChangeExtension(base1, ".fs") | |
| let projFileName = Path.ChangeExtension(base1, ".fsproj") | |
| let dllName = Path.ChangeExtension(base1, ".dll") | |
| let options = | |
| let syslib name = | |
| System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86) | |
| + @"\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\" | |
| + (name + ".dll") | |
| let fscore4400 = | |
| System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86) | |
| + @"\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.4.0.0\FSharp.Core.dll" | |
| checker.GetProjectOptionsFromCommandLineArgs | |
| (projFileName, | |
| [| yield "--simpleresolution" | |
| yield "--noframework" | |
| yield "--debug:full" | |
| yield "--define:DEBUG" | |
| yield "--optimize-" | |
| yield "--out:" + dllName | |
| yield "--warn:3" | |
| yield "--fullpaths" | |
| yield "--flaterrors" | |
| yield "--target:library" | |
| yield fileName1 | |
| let defaultReferences = | |
| [ syslib "mscorlib" | |
| syslib "System" | |
| syslib "System.Core" | |
| syslib "System.Xml" | |
| syslib "System.Configuration" | |
| fscore4400 | |
| asm.Location ] | |
| for r in defaultReferences do | |
| yield "-r:" + r |] | |
| ) | |
| let x = checker.ParseAndCheckProject(options) |> Async.RunSynchronously | |
| x.ProjectContext.GetReferencedAssemblies() | |
| |> Seq.find (fun x -> x.SimpleName = asm.GetName().Name) | |
| let test() = | |
| let assembly = loadAssembly() | |
| let thisModule = assembly.Contents.Entities |> Seq.find (fun x -> x.DisplayName = "InferredFloatRepro") | |
| let test name (x: FSharpMemberOrFunctionOrValue) = | |
| let arg = x.FullType.GenericArguments.[0] | |
| printfn "%s.IsAbbreviation: %b" name arg.IsAbbreviation | |
| printfn "%s.AbbreviatedType: %A" name arg.AbbreviatedType | |
| printfn "%s.TypeDefinition.TryFullName: %A" name arg.TypeDefinition.TryFullName | |
| printfn "%s.GenericArguments: %A" name (arg.GenericArguments |> Seq.map (fun x -> x.TypeDefinition.DisplayName)) | |
| test "inferredFloat" (thisModule.MembersFunctionsAndValues |> Seq.find (fun x -> x.DisplayName = "inferredFloatFunction")) | |
| test "annotatedFloat" (thisModule.MembersFunctionsAndValues |> Seq.find (fun x -> x.DisplayName = "annotatedFloatFunction")) | |
| test "inferenceInt" (thisModule.MembersFunctionsAndValues |> Seq.find (fun x -> x.DisplayName = "inferredIntFunction")) | |
| () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
execution result