diff --git a/src/Compiler/Service/TransparentCompiler.fs b/src/Compiler/Service/TransparentCompiler.fs index 124be183fd9..1d3ccf36906 100644 --- a/src/Compiler/Service/TransparentCompiler.fs +++ b/src/Compiler/Service/TransparentCompiler.fs @@ -1198,29 +1198,16 @@ type internal TransparentCompiler tcConfig.flatErrors ) - use _ = - new CompilationGlobalsScope(errHandler.DiagnosticsLogger, BuildPhase.TypeCheck) - // Apply nowarns to tcConfig (may generate errors, so ensure diagnosticsLogger is installed) let tcConfig = ApplyNoWarnsToTcConfig(tcConfig, parsedMainInput, Path.GetDirectoryName mainInputFileName) - // update the error handler with the modified tcConfig - errHandler.DiagnosticOptions <- tcConfig.diagnosticsOptions - let diagnosticsLogger = errHandler.DiagnosticsLogger - //let capturingDiagnosticsLogger = CapturingDiagnosticsLogger("TypeCheck") - - //let diagnosticsLogger = - // GetDiagnosticsLoggerFilteringByScopedPragmas( - // false, - // input.ScopedPragmas, - // tcConfig.diagnosticsOptions, - // capturingDiagnosticsLogger - // ) + let diagnosticsLogger = + GetDiagnosticsLoggerFilteringByScopedPragmas(false, input.ScopedPragmas, tcConfig.diagnosticsOptions, diagnosticsLogger) - //use _ = new CompilationGlobalsScope(diagnosticsLogger, BuildPhase.TypeCheck) + use _ = new CompilationGlobalsScope(diagnosticsLogger, BuildPhase.TypeCheck) //beforeFileChecked.Trigger fileName diff --git a/tests/FSharp.Compiler.ComponentTests/ConstraintSolver/ObjInference.fs b/tests/FSharp.Compiler.ComponentTests/ConstraintSolver/ObjInference.fs index 32950d8ba4c..d12a462f384 100644 --- a/tests/FSharp.Compiler.ComponentTests/ConstraintSolver/ObjInference.fs +++ b/tests/FSharp.Compiler.ComponentTests/ConstraintSolver/ObjInference.fs @@ -34,13 +34,14 @@ let x = deserialize "" |> f""", 3, 9, 3, 28 [] [] let ``Warning is emitted when type Obj is inferred``(code: string, line1: int, col1: int, line2: int, col2: int) = + let code = $"module M\n{code}" FSharp code |> withErrorRanges |> withWarnOn 3559 |> withLangVersion80 - |> typecheck + |> compile |> shouldFail - |> withSingleDiagnostic (Information 3559, Line line1, Col col1, Line line2, Col col2, message) + |> withSingleDiagnostic (Warning 3559, Line (line1 + 1), Col col1, Line (line2 + 1), Col col2, message) let quotableNoWarningCases = [ @@ -110,13 +111,13 @@ let f () = x = x |> ignore""" // measure is inferred as 1, but that's not covere [] [] let ``Warn also inside quotations of acceptable code``(expr: string, line1: int, col1: int, line2: int, col2: int) = - sprintf "<@ %s @> |> ignore" expr + sprintf "module M\n<@ %s @> |> ignore" expr |> FSharp |> withWarnOn 3559 |> withLangVersion80 - |> typecheck + |> compile |> shouldFail - |> withSingleDiagnostic (Information 3559, Line line1, Col (col1 + 3), Line line2, Col (col2 + 3), message) + |> withSingleDiagnostic (Warning 3559, Line (line1 + 1), Col (col1 + 3), Line (line2 + 1), Col (col2 + 3), message) [] [] diff --git a/tests/service/ExprTests.fs b/tests/service/ExprTests.fs index 7b35568e38d..1371c24f231 100644 --- a/tests/service/ExprTests.fs +++ b/tests/service/ExprTests.fs @@ -3605,3 +3605,27 @@ let ``Test ProjectForWitnesses4 GetWitnessPassingInfo`` useTransparentCompiler = printfn "actual:\n\n%A" actual actual |> shouldPairwiseEqual expected + +module internal ProjectForNoWarnHashDirective = + + let fileSource1 = """ +module N.M +#nowarn "40" +let rec f = new System.EventHandler(fun _ _ -> f.Invoke(null,null)) +""" + + let createOptions() = createOptionsAux [fileSource1] [] + +[] +[] +[] +let ``Test NoWarn HashDirective`` useTransparentCompiler = + let cleanup, options = ProjectForNoWarnHashDirective.createOptions() + use _holder = cleanup + let exprChecker = FSharpChecker.Create(keepAssemblyContents=true, useTransparentCompiler=useTransparentCompiler) + let wholeProjectResults = exprChecker.ParseAndCheckProject(options) |> Async.RunImmediate + + for e in wholeProjectResults.Diagnostics do + printfn "ProjectForNoWarnHashDirective error: <<<%s>>>" e.Message + + wholeProjectResults.Diagnostics.Length |> shouldEqual 0