diff --git a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md index a26f7e77ebe..7d4162f804e 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md @@ -1,5 +1,6 @@ ### Fixed +* Honor `--nowarn` and `--warnaserror` for warnings emitted during command-line option parsing ([Issue #19576](https://github.com/dotnet/fsharp/issues/19576), [PR #19776](https://github.com/dotnet/fsharp/pull/19776)) * Fix `[]` prefix attributes being silently dropped on class members, and fix false-positive `AllowMultiple=false` errors when `[]` and `[]` are applied to the same binding. ([Issue #17904](https://github.com/dotnet/fsharp/issues/17904), [Issue #19020](https://github.com/dotnet/fsharp/issues/19020), [PR #19738](https://github.com/dotnet/fsharp/pull/19738)) * Fix attributes on return type of unparenthesized tuple methods being silently dropped from IL. ([Issue #462](https://github.com/dotnet/fsharp/issues/462), [PR #19714](https://github.com/dotnet/fsharp/pull/19714)) * Fix internal error FS0073 "Undefined or unsolved type variable" in IlxGen when nested inline SRTP functions with multiple overloads leave unsolved typars in the non-witness codegen path. ([Issue #19709](https://github.com/dotnet/fsharp/issues/19709), [PR #19710](https://github.com/dotnet/fsharp/pull/19710)) diff --git a/src/Compiler/Driver/fsc.fs b/src/Compiler/Driver/fsc.fs index 3b6a3bfef18..1912f13ff71 100644 --- a/src/Compiler/Driver/fsc.fs +++ b/src/Compiler/Driver/fsc.fs @@ -119,10 +119,9 @@ type IDiagnosticsLoggerProvider = type CapturingDiagnosticsLogger with - /// Commit the delayed diagnostics via a fresh temporary logger of the right kind. member x.CommitDelayedDiagnostics(diagnosticsLoggerProvider: IDiagnosticsLoggerProvider, tcConfigB, exiter) = let diagnosticsLogger = diagnosticsLoggerProvider.CreateLogger(tcConfigB, exiter) - x.CommitDelayedDiagnostics diagnosticsLogger + x.CommitDelayedDiagnostics(GetDiagnosticsLoggerFilteringByScopedNowarn(tcConfigB.diagnosticsOptions, diagnosticsLogger)) /// The default DiagnosticsLogger implementation, reporting messages to the Console up to the maxerrors maximum type ConsoleLoggerProvider() = @@ -578,7 +577,9 @@ let main1 SetThreadDiagnosticsLoggerNoUnwind diagnosticsLogger // Forward all errors from flags - delayForFlagsLogger.CommitDelayedDiagnostics diagnosticsLogger + delayForFlagsLogger.CommitDelayedDiagnostics( + GetDiagnosticsLoggerFilteringByScopedNowarn(tcConfigB.diagnosticsOptions, diagnosticsLogger) + ) if not tcConfigB.continueAfterParseFailure then AbortOnError(diagnosticsLogger, exiter) diff --git a/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/warn/nowarn_for_cmdline_warnings.fs b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/warn/nowarn_for_cmdline_warnings.fs new file mode 100644 index 00000000000..b6855e188db --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/warn/nowarn_for_cmdline_warnings.fs @@ -0,0 +1,78 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace CompilerOptions.Fsc + +open Xunit +open FSharp.Test +open FSharp.Test.Compiler + +/// Regression tests for https://github.com/dotnet/fsharp/issues/19576 +module ``Nowarn for command-line option warnings`` = + + [] + let ``command-line option warning is emitted`` () = + FSharp "module Module" + |> withOptions [ "--extraoptimizationloops:1" ] + |> ignoreWarnings + |> compile + |> shouldSucceed + |> withWarningCode 75 + |> ignore + + [] + let ``--nowarn suppresses command-line option warning`` () = + FSharp "module Module" + |> withOptions [ "--extraoptimizationloops:1"; "--nowarn:75" ] + |> compile + |> shouldSucceed + + [] + let ``--nowarn suppresses only the targeted warning`` () = + FSharp "module Module" + |> withOptions [ "--extraoptimizationloops:1"; "--test:NoSuchTestFlag"; "--nowarn:75" ] + |> ignoreWarnings + |> compile + |> shouldSucceed + |> withWarningCode 1063 + |> ignore + + [] + let ``--nowarn 3551 suppresses duplicate source file warning`` () = + let file = + SourceCodeFileKind.Fs( + { FileName = "test.fs" + SourceText = Some """printfn "Hello" """ } + ) + + fsFromString file + |> FS + |> asExe + |> withAdditionalSourceFile file + |> withNoWarn 3551 + |> compile + |> shouldSucceed + + [] + let ``--warnaserror+ promotes command-line option warning to error`` () = + FSharp "module Module" + |> withOptions [ "--warnaserror+"; "--extraoptimizationloops:1" ] + |> compile + |> shouldFail + |> withErrorCode 75 + |> ignore + + [] + let ``--warnaserror+ with --nowarn suppresses rather than errors`` () = + FSharp "module Module" + |> withOptions [ "--warnaserror+"; "--extraoptimizationloops:1"; "--nowarn:75" ] + |> compile + |> shouldSucceed + + [] + let ``--warnaserror 75 with --nowarn 75 still errors because specific warnaserror wins`` () = + FSharp "module Module" + |> withOptions [ "--warnaserror:75"; "--extraoptimizationloops:1"; "--nowarn:75" ] + |> compile + |> shouldFail + |> withErrorCode 75 + |> ignore diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 50937f9945b..dfc14e9ef4d 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -419,6 +419,7 @@ +