Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions src/Compiler/Service/TransparentCompiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ let x = deserialize "" |> f""", 3, 9, 3, 28
[<Theory>]
[<MemberData(nameof(warningCases))>]
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 =
[
Expand Down Expand Up @@ -110,13 +111,13 @@ let f () = x = x |> ignore""" // measure is inferred as 1, but that's not covere
[<Theory>]
[<MemberData(nameof(quotableWarningCases))>]
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)

[<Theory>]
[<MemberData(nameof(quotableNoWarningCases))>]
Expand Down
24 changes: 24 additions & 0 deletions tests/service/ExprTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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] []

[<TestCase(false)>]
[<TestCase(true)>]
[<Test>]
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