From 57bca6049dfb44e5747db584cb285ae4a5c6af7e Mon Sep 17 00:00:00 2001 From: 0101 <0101@innit.cz> Date: Thu, 15 Feb 2024 18:22:58 +0100 Subject: [PATCH 1/8] test --- .../FSharpChecker/CommonWorkflows.fs | 20 +++++++++++++++++++ .../ProjectGeneration.fs | 13 ++++++++++++ 2 files changed, 33 insertions(+) diff --git a/tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs b/tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs index 735e7828b89..59b1741b669 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs +++ b/tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs @@ -167,3 +167,23 @@ let GetAllUsesOfAllSymbols() = traceProvider.Dispose() if result.Length <> 79 then failwith $"Expected 79 symbolUses, got {result.Length}:\n%A{result}" + +[] +let ``We don't lose subsequent diagnostics when there's error in one file`` () = + let project = + { SyntheticProject.Create( + { sourceFile "First" [] with + Source = "module AbstractBaseClass.File1 \n\n\n a" }, + { sourceFile "Second" [] with + Source = """module AbstractBaseClass.File2 + + type AbstractBaseClass() = + + abstract P: int""" }) with + AutoAddModules = false + SkipInitialCheck = true } + + project.Workflow { + checkFile "First" (expectErrorCodes ["FS0039"]) + checkFile "Second" (expectErrorCodes ["FS0054"; "FS0365"]) + } diff --git a/tests/FSharp.Test.Utilities/ProjectGeneration.fs b/tests/FSharp.Test.Utilities/ProjectGeneration.fs index 2157d8fb7fe..9d71ef743c1 100644 --- a/tests/FSharp.Test.Utilities/ProjectGeneration.fs +++ b/tests/FSharp.Test.Utilities/ProjectGeneration.fs @@ -725,6 +725,19 @@ module ProjectOperations = then failwith "Expected errors, but there were none" + let expectErrorCodes codes parseAndCheckResults _ = + let (parseResult: FSharpParseFileResults), _checkResult = parseAndCheckResults + + if not parseResult.ParseHadErrors then + let checkResult = getTypeCheckResult parseAndCheckResults + let actualCodes = checkResult.Diagnostics |> Seq.map (fun d -> d.ErrorNumberText) |> Set + let codes = Set.ofSeq codes + if actualCodes <> codes then + failwith $"Expected error codes {codes} but got {actualCodes}. \n%A{checkResult.Diagnostics}" + + else + failwith $"There were parse errors: %A{parseResult.Diagnostics}" + let expectSignatureChanged result (oldSignature: string, newSignature: string) = expectOk result () Assert.NotEqual(oldSignature, newSignature) From a062710d616c96edbf0af1614d5e5e6c5b725553 Mon Sep 17 00:00:00 2001 From: 0101 <0101@innit.cz> Date: Fri, 16 Feb 2024 20:03:17 +0100 Subject: [PATCH 2/8] See what happens... --- src/Compiler/Service/FSharpCheckerResults.fs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Compiler/Service/FSharpCheckerResults.fs b/src/Compiler/Service/FSharpCheckerResults.fs index 045e0aae7a0..faebbf8b0cd 100644 --- a/src/Compiler/Service/FSharpCheckerResults.fs +++ b/src/Compiler/Service/FSharpCheckerResults.fs @@ -2910,9 +2910,9 @@ module internal ParseAndCheckFile = errHandler.DiagnosticOptions <- tcConfig.diagnosticsOptions // Play background errors and warnings for this file. - do - for err, severity in backgroundDiagnostics do - diagnosticSink (err, severity) + //do + // for err, severity in backgroundDiagnostics do + // diagnosticSink (err, severity) // If additional references were brought in by the preprocessor then we need to process them ApplyLoadClosure(tcConfig, parsedMainInput, mainInputFileName, loadClosure, tcImports, backgroundDiagnostics) From 4e410d5663a15b7c8ec68fc1f6e3e3bde90fc875 Mon Sep 17 00:00:00 2001 From: Petr Pokorny Date: Mon, 19 Feb 2024 14:50:59 +0100 Subject: [PATCH 3/8] potential fix --- src/Compiler/Service/BackgroundCompiler.fs | 2 +- src/Compiler/Service/FSharpCheckerResults.fs | 6 +++--- src/Compiler/Service/IncrementalBuild.fs | 2 ++ src/Compiler/Service/IncrementalBuild.fsi | 2 ++ .../FSharpChecker/CommonWorkflows.fs | 16 ++++++++++++---- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Compiler/Service/BackgroundCompiler.fs b/src/Compiler/Service/BackgroundCompiler.fs index 54bea5584ad..d654390fca5 100644 --- a/src/Compiler/Service/BackgroundCompiler.fs +++ b/src/Compiler/Service/BackgroundCompiler.fs @@ -719,7 +719,7 @@ type internal BackgroundCompiler tcInfo.tcState, tcInfo.moduleNamesDict, loadClosure, - tcInfo.TcDiagnostics, + builder.InitialErrors, options.IsIncompleteTypeCheckEnvironment, options, Some builder, diff --git a/src/Compiler/Service/FSharpCheckerResults.fs b/src/Compiler/Service/FSharpCheckerResults.fs index faebbf8b0cd..045e0aae7a0 100644 --- a/src/Compiler/Service/FSharpCheckerResults.fs +++ b/src/Compiler/Service/FSharpCheckerResults.fs @@ -2910,9 +2910,9 @@ module internal ParseAndCheckFile = errHandler.DiagnosticOptions <- tcConfig.diagnosticsOptions // Play background errors and warnings for this file. - //do - // for err, severity in backgroundDiagnostics do - // diagnosticSink (err, severity) + do + for err, severity in backgroundDiagnostics do + diagnosticSink (err, severity) // If additional references were brought in by the preprocessor then we need to process them ApplyLoadClosure(tcConfig, parsedMainInput, mainInputFileName, loadClosure, tcImports, backgroundDiagnostics) diff --git a/src/Compiler/Service/IncrementalBuild.fs b/src/Compiler/Service/IncrementalBuild.fs index f59a1e9b6a5..573c78f18c5 100644 --- a/src/Compiler/Service/IncrementalBuild.fs +++ b/src/Compiler/Service/IncrementalBuild.fs @@ -1182,6 +1182,8 @@ type IncrementalBuilder(initialState: IncrementalBuilderInitialState, state: Inc member _.ProjectChecked = projectChecked.Publish + member _.InitialErrors = initialState.initialErrors + #if !NO_TYPEPROVIDERS member _.ImportsInvalidatedByTypeProvider = importsInvalidatedByTypeProvider.Publish #endif diff --git a/src/Compiler/Service/IncrementalBuild.fsi b/src/Compiler/Service/IncrementalBuild.fsi index 0dedfb02948..d30e6446485 100644 --- a/src/Compiler/Service/IncrementalBuild.fsi +++ b/src/Compiler/Service/IncrementalBuild.fsi @@ -182,6 +182,8 @@ type internal IncrementalBuilder = /// overall analysis results for the project will be quick. member ProjectChecked: IEvent + member InitialErrors: (PhasedDiagnostic * FSharpDiagnosticSeverity) array + #if !NO_TYPEPROVIDERS /// Raised when the build is invalidated. member ImportsInvalidatedByTypeProvider: IEvent diff --git a/tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs b/tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs index 59b1741b669..042633ec022 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs +++ b/tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs @@ -173,16 +173,24 @@ let ``We don't lose subsequent diagnostics when there's error in one file`` () = let project = { SyntheticProject.Create( { sourceFile "First" [] with - Source = "module AbstractBaseClass.File1 \n\n\n a" }, + Source = """module AbstractBaseClass.File1 + + let foo x = () + + a""" }, { sourceFile "Second" [] with Source = """module AbstractBaseClass.File2 - type AbstractBaseClass() = + open AbstractBaseClass.File1 - abstract P: int""" }) with + let goo = foo 1 + + type AbstractBaseClass() = + + abstract P: int""" }) with AutoAddModules = false SkipInitialCheck = true } - + project.Workflow { checkFile "First" (expectErrorCodes ["FS0039"]) checkFile "Second" (expectErrorCodes ["FS0054"; "FS0365"]) From 2ca2c6adbc70d4f325c7bdfc3289e11693f124a9 Mon Sep 17 00:00:00 2001 From: Petr Pokorny Date: Mon, 19 Feb 2024 19:04:42 +0100 Subject: [PATCH 4/8] revert --- src/Compiler/Service/BackgroundCompiler.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/Service/BackgroundCompiler.fs b/src/Compiler/Service/BackgroundCompiler.fs index d654390fca5..54bea5584ad 100644 --- a/src/Compiler/Service/BackgroundCompiler.fs +++ b/src/Compiler/Service/BackgroundCompiler.fs @@ -719,7 +719,7 @@ type internal BackgroundCompiler tcInfo.tcState, tcInfo.moduleNamesDict, loadClosure, - builder.InitialErrors, + tcInfo.TcDiagnostics, options.IsIncompleteTypeCheckEnvironment, options, Some builder, From 723138c871adf676931006cf6eaa25516e466ad1 Mon Sep 17 00:00:00 2001 From: 0101 <0101@innit.cz> Date: Tue, 20 Feb 2024 18:28:52 +0100 Subject: [PATCH 5/8] what about this --- src/Compiler/Service/FSharpCheckerResults.fs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Compiler/Service/FSharpCheckerResults.fs b/src/Compiler/Service/FSharpCheckerResults.fs index 045e0aae7a0..77f384fcf42 100644 --- a/src/Compiler/Service/FSharpCheckerResults.fs +++ b/src/Compiler/Service/FSharpCheckerResults.fs @@ -2909,10 +2909,7 @@ module internal ParseAndCheckFile = // update the error handler with the modified tcConfig errHandler.DiagnosticOptions <- tcConfig.diagnosticsOptions - // Play background errors and warnings for this file. - do - for err, severity in backgroundDiagnostics do - diagnosticSink (err, severity) + // If additional references were brought in by the preprocessor then we need to process them ApplyLoadClosure(tcConfig, parsedMainInput, mainInputFileName, loadClosure, tcImports, backgroundDiagnostics) @@ -2957,6 +2954,11 @@ module internal ParseAndCheckFile = return ((tcState.TcEnvFromSignatures, EmptyTopAttrs, [], [ mty ]), tcState) } + // Play background errors and warnings for this file. + do + for err, severity in backgroundDiagnostics do + diagnosticSink (err, severity) + let (tcEnvAtEnd, _, implFiles, ccuSigsForFiles), tcState = resOpt let symbolEnv = SymbolEnv(tcGlobals, tcState.Ccu, Some tcState.CcuSig, tcImports) From 7270d82fc4c4b58e90bad79ec20892c43f3839d4 Mon Sep 17 00:00:00 2001 From: 0101 <0101@innit.cz> Date: Tue, 20 Feb 2024 20:06:35 +0100 Subject: [PATCH 6/8] f --- src/Compiler/Service/FSharpCheckerResults.fs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Compiler/Service/FSharpCheckerResults.fs b/src/Compiler/Service/FSharpCheckerResults.fs index 77f384fcf42..87c45e2fa3c 100644 --- a/src/Compiler/Service/FSharpCheckerResults.fs +++ b/src/Compiler/Service/FSharpCheckerResults.fs @@ -2909,8 +2909,6 @@ module internal ParseAndCheckFile = // update the error handler with the modified tcConfig errHandler.DiagnosticOptions <- tcConfig.diagnosticsOptions - - // If additional references were brought in by the preprocessor then we need to process them ApplyLoadClosure(tcConfig, parsedMainInput, mainInputFileName, loadClosure, tcImports, backgroundDiagnostics) From 31a8ef2fff88f2f9f399daff7d8f989bfffa662f Mon Sep 17 00:00:00 2001 From: Petr Pokorny Date: Wed, 21 Feb 2024 11:17:10 +0100 Subject: [PATCH 7/8] Release note --- docs/release-notes/.FSharp.Compiler.Service/8.0.300.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md index 672209d2ed1..b620c1445b5 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md @@ -11,6 +11,7 @@ * `[]` member should not produce property symbol. ([Issue #16640](https://github.com/dotnet/fsharp/issues/16640), [PR #16658](https://github.com/dotnet/fsharp/pull/16658)) * Fix discriminated union initialization. ([#PR 16661](https://github.com/dotnet/fsharp/pull/16661)) * Allow calling method with both Optional and ParamArray. ([#PR 16688](https://github.com/dotnet/fsharp/pull/16688), [suggestions #1120](https://github.com/fsharp/fslang-suggestions/issues/1120)) +* Return diagnostics that got suppressed by errors in previous files. ([PR #16719](https://github.com/dotnet/fsharp/pull/16719)) ### Added From 59393289e796687b403d8564a931feba36ab8a3d Mon Sep 17 00:00:00 2001 From: 0101 <0101@innit.cz> Date: Wed, 21 Feb 2024 11:29:09 +0100 Subject: [PATCH 8/8] revert --- src/Compiler/Service/IncrementalBuild.fs | 2 -- src/Compiler/Service/IncrementalBuild.fsi | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/Compiler/Service/IncrementalBuild.fs b/src/Compiler/Service/IncrementalBuild.fs index 573c78f18c5..f59a1e9b6a5 100644 --- a/src/Compiler/Service/IncrementalBuild.fs +++ b/src/Compiler/Service/IncrementalBuild.fs @@ -1182,8 +1182,6 @@ type IncrementalBuilder(initialState: IncrementalBuilderInitialState, state: Inc member _.ProjectChecked = projectChecked.Publish - member _.InitialErrors = initialState.initialErrors - #if !NO_TYPEPROVIDERS member _.ImportsInvalidatedByTypeProvider = importsInvalidatedByTypeProvider.Publish #endif diff --git a/src/Compiler/Service/IncrementalBuild.fsi b/src/Compiler/Service/IncrementalBuild.fsi index d30e6446485..0dedfb02948 100644 --- a/src/Compiler/Service/IncrementalBuild.fsi +++ b/src/Compiler/Service/IncrementalBuild.fsi @@ -182,8 +182,6 @@ type internal IncrementalBuilder = /// overall analysis results for the project will be quick. member ProjectChecked: IEvent - member InitialErrors: (PhasedDiagnostic * FSharpDiagnosticSeverity) array - #if !NO_TYPEPROVIDERS /// Raised when the build is invalidated. member ImportsInvalidatedByTypeProvider: IEvent