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
4 changes: 2 additions & 2 deletions src/Compiler/Service/FSharpProjectSnapshot.fs
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ type internal FSharpParsedFile
SyntaxTreeHash: byte array,
SourceText: ISourceText,
ParsedInput: ParsedInput,
ParseErrors: (PhasedDiagnostic * FSharpDiagnosticSeverity)[]
ParseDiagnostics: (PhasedDiagnostic * FSharpDiagnosticSeverity)[]
) =

member _.FileName = FileName
member _.SourceText = SourceText
member _.ParsedInput = ParsedInput
member _.ParseErrors = ParseErrors
member _.ParseDiagnostics = ParseDiagnostics

member val IsSignatureFile = FileName |> isSignatureFile

Expand Down
6 changes: 4 additions & 2 deletions src/Compiler/Service/TransparentCompiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,9 @@ type internal TransparentCompiler

let sink = TcResultsSinkImpl(tcGlobals, file.SourceText)

let hadParseErrors = not (Array.isEmpty file.ParseErrors)
let hadParseErrors =
file.ParseDiagnostics
|> Array.exists (snd >> (=) FSharpDiagnosticSeverity.Error)

let input, moduleNamesDict =
DeduplicateParsedInputModuleName prevTcInfo.moduleNamesDict input
Expand Down Expand Up @@ -1448,7 +1450,7 @@ type internal TransparentCompiler
tcConfig.diagnosticsOptions,
false,
file.FileName,
parsedFile.ParseErrors,
parsedFile.ParseDiagnostics,
suggestNamesForErrors,
tcConfig.flatErrors,
None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -960,3 +960,54 @@ let ``Background compiler and Transparent compiler return the same options`` ()
Assert.Equal<string list>(backgroundSnapshot.OtherOptions, transparentSnapshot.OtherOptions)
Assert.Equal<ProjectSnapshot.ReferenceOnDisk list>(backgroundSnapshot.ReferencesOnDisk, transparentSnapshot.ReferencesOnDisk)
}

[<Theory>]
[<InlineData(false)>]
[<InlineData(true)>]
let ``Unused warning should still produce after parse warning`` useTransparentCompiler =

// There should be parse warning because of the space in the file name:
// warning FS0221: The declarations in this file will be placed in an implicit module 'As 01' based on the file name 'As 01.fs'.
// However this is not a valid F# identifier, so the contents will not be accessible from other files. Consider renaming the file or adding a 'module' or 'namespace' declaration at the top of the file.

let project =
{ SyntheticProject.Create(
{ sourceFile "As 01" [] with
Source = """
do
let _ as b = ()
()

// For more information see https://aka.ms/fsharp-console-apps
printfn "Hello from F#"
"""
SignatureFile = No

}) with
AutoAddModules = false
OtherOptions = [
"--target:exe"
"--warn:3"
"--warnon:1182"
"--warnaserror:3239"
"--noframework"
]
}

let expectTwoWarnings (_parseResult:FSharpParseFileResults, checkAnswer: FSharpCheckFileAnswer) (_, _) =
match checkAnswer with
| FSharpCheckFileAnswer.Aborted -> failwith "Should not have aborted"
| FSharpCheckFileAnswer.Succeeded checkResults ->
let hasParseWarning =
checkResults.Diagnostics
|> Array.exists (fun diag -> diag.Severity = FSharpDiagnosticSeverity.Warning && diag.ErrorNumber = 221)
Assert.True(hasParseWarning, "Expected parse warning FS0221")

let hasCheckWarning =
checkResults.Diagnostics
|> Array.exists (fun diag -> diag.Severity = FSharpDiagnosticSeverity.Warning && diag.ErrorNumber = 1182)
Assert.True(hasCheckWarning, "Expected post inference warning FS1182")

ProjectWorkflowBuilder(project, useTransparentCompiler = useTransparentCompiler) {
checkFile "As 01" expectTwoWarnings
}