From de9dde68cce675a2229334923d47782080b52412 Mon Sep 17 00:00:00 2001 From: nojaf Date: Thu, 1 Feb 2024 16:40:37 +0100 Subject: [PATCH] Transparent compiler doesn't respect #nowarn in test. --- Foo.fs | 13 ++++++ Foo.rsp | 7 +++ .../FSharpChecker/TransparentCompiler.fs | 5 +- .../ProjectGeneration.fs | 46 ++++++++++++------- 4 files changed, 53 insertions(+), 18 deletions(-) create mode 100644 Foo.fs create mode 100644 Foo.rsp diff --git a/Foo.fs b/Foo.fs new file mode 100644 index 00000000000..a35a6d6e61a --- /dev/null +++ b/Foo.fs @@ -0,0 +1,13 @@ +module Meh + +let bar (name:string) : 'a = failwith<'a> "todo" + +#nowarn "40" + +type Foo () = + member __.Bar (name : string) : unit -> 'a = + let rec prov : (unit -> 'a) ref = ref (fun () -> + let p : (unit -> 'a) = bar name + prov := p + p()) + fun () -> (!prov)() \ No newline at end of file diff --git a/Foo.rsp b/Foo.rsp new file mode 100644 index 00000000000..505d58f3e17 --- /dev/null +++ b/Foo.rsp @@ -0,0 +1,7 @@ +--nowarn:FS3370,FS0075 +--warn:4 +--warnaserror +--warnaserror:3239 +--warnaserror-:44 +-a +Foo.fs \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/FSharpChecker/TransparentCompiler.fs b/tests/FSharp.Compiler.ComponentTests/FSharpChecker/TransparentCompiler.fs index 90dc85c4a33..1b03c2b7781 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharpChecker/TransparentCompiler.fs +++ b/tests/FSharp.Compiler.ComponentTests/FSharpChecker/TransparentCompiler.fs @@ -806,7 +806,8 @@ module Stuff = /// References projects are expected to have been built. let localResponseFiles = [| - @"C:\Projects\fantomas\src\Fantomas.Core.Tests\Fantomas.Core.Tests.rsp" + // @"C:\Projects\fantomas\src\Fantomas.Core.Tests\Fantomas.Core.Tests.rsp" + Path.Combine(__SOURCE_DIRECTORY__, "..", "..", "..", "Foo.rsp") |] |> Array.collect (fun f -> [| @@ -816,7 +817,7 @@ let localResponseFiles = ) // Uncomment this attribute if you want run this test against local response files. -// [] +[] [] let ``TypeCheck last file in project with transparent compiler`` useTransparentCompiler responseFile = let responseFile = FileInfo responseFile diff --git a/tests/FSharp.Test.Utilities/ProjectGeneration.fs b/tests/FSharp.Test.Utilities/ProjectGeneration.fs index 144e535bccb..695a1ad0ce0 100644 --- a/tests/FSharp.Test.Utilities/ProjectGeneration.fs +++ b/tests/FSharp.Test.Utilities/ProjectGeneration.fs @@ -310,13 +310,33 @@ type SyntheticProject = } |> String.concat "\n" - let baseOptions, _ = - checker.GetProjectOptionsFromScript( - "file.fsx", - SourceText.ofString referenceScript, - assumeDotNetFramework = false - ) - |> Async.RunSynchronously + let isRealProject = this.SourceFiles |> List.forall (fun sf -> sf.IsPhysicalFile) + + let otherOptions = + if isRealProject then + List.toArray this.OtherOptions + else + + let baseOptions = + if isRealProject then + Unchecked.defaultof + else + + checker.GetProjectOptionsFromScript( + "file.fsx", + SourceText.ofString referenceScript, + assumeDotNetFramework = false + ) + |> Async.RunSynchronously + |> fst + + Set [ + yield! baseOptions.OtherOptions + "--optimize+" + for p in this.DependsOn do + $"-r:{p.OutputFilename}" + yield! this.OtherOptions ] + |> Set.toArray { ProjectFileName = this.ProjectFileName @@ -327,14 +347,7 @@ type SyntheticProject = this.ProjectDir ++ f.SignatureFileName this.ProjectDir ++ f.FileName |] - OtherOptions = - Set [ - yield! baseOptions.OtherOptions - "--optimize+" - for p in this.DependsOn do - $"-r:{p.OutputFilename}" - yield! this.OtherOptions ] - |> Set.toArray + OtherOptions = otherOptions ReferencedProjects = [| for p in this.DependsOn do FSharpReferencedProject.FSharpReference(p.OutputFilename, p.GetProjectOptions checker) |] @@ -343,7 +356,8 @@ type SyntheticProject = LoadTime = DateTime() UnresolvedReferences = None OriginalLoadReferences = [] - Stamp = None } + Stamp = None + } OptionsCache[cacheKey]