Skip to content

Commit 51013da

Browse files
0101vzarytovskii
andauthored
Fix #16708 / Some errors are not reported if any of previous files contain errors (#16719)
* test * See what happens... * potential fix * revert * what about this * f * Release note * revert --------- Co-authored-by: Vlad Zarytovskii <[email protected]>
1 parent 72baf1e commit 51013da

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

docs/release-notes/.FSharp.Compiler.Service/8.0.300.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* `[<CliEvent>]` member should not produce property symbol. ([Issue #16640](https://github.com/dotnet/fsharp/issues/16640), [PR #16658](https://github.com/dotnet/fsharp/pull/16658))
1414
* Fix discriminated union initialization. ([#PR 16661](https://github.com/dotnet/fsharp/pull/16661))
1515
* 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))
16+
* Return diagnostics that got suppressed by errors in previous files. ([PR #16719](https://github.com/dotnet/fsharp/pull/16719))
1617
* Fix release inline optimization, which leads to MethodAccessException if used with `assembly:InternalsVisibleTo`` attribute. ([Issue #16105](https://github.com/dotnet/fsharp/issues/16105), ([PR #16737](https://github.com/dotnet/fsharp/pull/16737))
1718
* Enforce AttributeTargets on let values and functions. ([PR #16692](https://github.com/dotnet/fsharp/pull/16692))
1819
* Enforce AttributeTargets on union case declarations. ([PR #16764](https://github.com/dotnet/fsharp/pull/16764))

src/Compiler/Service/FSharpCheckerResults.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,11 +2909,6 @@ module internal ParseAndCheckFile =
29092909
// update the error handler with the modified tcConfig
29102910
errHandler.DiagnosticOptions <- tcConfig.diagnosticsOptions
29112911

2912-
// Play background errors and warnings for this file.
2913-
do
2914-
for err, severity in backgroundDiagnostics do
2915-
diagnosticSink (err, severity)
2916-
29172912
// If additional references were brought in by the preprocessor then we need to process them
29182913
ApplyLoadClosure(tcConfig, parsedMainInput, mainInputFileName, loadClosure, tcImports, backgroundDiagnostics)
29192914

@@ -2957,6 +2952,11 @@ module internal ParseAndCheckFile =
29572952
return ((tcState.TcEnvFromSignatures, EmptyTopAttrs, [], [ mty ]), tcState)
29582953
}
29592954

2955+
// Play background errors and warnings for this file.
2956+
do
2957+
for err, severity in backgroundDiagnostics do
2958+
diagnosticSink (err, severity)
2959+
29602960
let (tcEnvAtEnd, _, implFiles, ccuSigsForFiles), tcState = resOpt
29612961

29622962
let symbolEnv = SymbolEnv(tcGlobals, tcState.Ccu, Some tcState.CcuSig, tcImports)

tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,31 @@ let GetAllUsesOfAllSymbols() =
166166
traceProvider.Dispose()
167167

168168
if result.Length <> 79 then failwith $"Expected 79 symbolUses, got {result.Length}:\n%A{result}"
169+
170+
[<Fact>]
171+
let ``We don't lose subsequent diagnostics when there's error in one file`` () =
172+
let project =
173+
{ SyntheticProject.Create(
174+
{ sourceFile "First" [] with
175+
Source = """module AbstractBaseClass.File1
176+
177+
let foo x = ()
178+
179+
a""" },
180+
{ sourceFile "Second" [] with
181+
Source = """module AbstractBaseClass.File2
182+
183+
open AbstractBaseClass.File1
184+
185+
let goo = foo 1
186+
187+
type AbstractBaseClass() =
188+
189+
abstract P: int""" }) with
190+
AutoAddModules = false
191+
SkipInitialCheck = true }
192+
193+
project.Workflow {
194+
checkFile "First" (expectErrorCodes ["FS0039"])
195+
checkFile "Second" (expectErrorCodes ["FS0054"; "FS0365"])
196+
}

tests/FSharp.Test.Utilities/ProjectGeneration.fs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,19 @@ module ProjectOperations =
725725
then
726726
failwith "Expected errors, but there were none"
727727

728+
let expectErrorCodes codes parseAndCheckResults _ =
729+
let (parseResult: FSharpParseFileResults), _checkResult = parseAndCheckResults
730+
731+
if not parseResult.ParseHadErrors then
732+
let checkResult = getTypeCheckResult parseAndCheckResults
733+
let actualCodes = checkResult.Diagnostics |> Seq.map (fun d -> d.ErrorNumberText) |> Set
734+
let codes = Set.ofSeq codes
735+
if actualCodes <> codes then
736+
failwith $"Expected error codes {codes} but got {actualCodes}. \n%A{checkResult.Diagnostics}"
737+
738+
else
739+
failwith $"There were parse errors: %A{parseResult.Diagnostics}"
740+
728741
let expectSignatureChanged result (oldSignature: string, newSignature: string) =
729742
expectOk result ()
730743
Assert.NotEqual<string>(oldSignature, newSignature)

0 commit comments

Comments
 (0)