Skip to content

Commit

Permalink
Fix #16708 / Some errors are not reported if any of previous files co…
Browse files Browse the repository at this point in the history
…ntain errors (#16719)

* test

* See what happens...

* potential fix

* revert

* what about this

* f

* Release note

* revert

---------

Co-authored-by: Vlad Zarytovskii <vzaritovsky@hotmail.com>
  • Loading branch information
0101 and vzarytovskii authored Mar 22, 2024
1 parent 72baf1e commit 51013da
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/8.0.300.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* `[<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))
* 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))
* 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))
* Enforce AttributeTargets on let values and functions. ([PR #16692](https://github.com/dotnet/fsharp/pull/16692))
* Enforce AttributeTargets on union case declarations. ([PR #16764](https://github.com/dotnet/fsharp/pull/16764))
Expand Down
10 changes: 5 additions & 5 deletions src/Compiler/Service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2909,11 +2909,6 @@ 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)

Expand Down Expand Up @@ -2957,6 +2952,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,31 @@ let GetAllUsesOfAllSymbols() =
traceProvider.Dispose()

if result.Length <> 79 then failwith $"Expected 79 symbolUses, got {result.Length}:\n%A{result}"

[<Fact>]
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
let foo x = ()
a""" },
{ sourceFile "Second" [] with
Source = """module AbstractBaseClass.File2
open AbstractBaseClass.File1
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"])
}
13 changes: 13 additions & 0 deletions tests/FSharp.Test.Utilities/ProjectGeneration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(oldSignature, newSignature)
Expand Down

0 comments on commit 51013da

Please sign in to comment.