Skip to content

Commit 061624b

Browse files
committed
Don't consider parse warnings as errors in ComputeTcIntermediate
1 parent 1da032a commit 061624b

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

src/Compiler/Service/FSharpProjectSnapshot.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ type internal FSharpParsedFile
149149
SyntaxTreeHash: byte array,
150150
SourceText: ISourceText,
151151
ParsedInput: ParsedInput,
152-
ParseErrors: (PhasedDiagnostic * FSharpDiagnosticSeverity)[]
152+
ParseDiagnostics: (PhasedDiagnostic * FSharpDiagnosticSeverity)[]
153153
) =
154154

155155
member _.FileName = FileName
156156
member _.SourceText = SourceText
157157
member _.ParsedInput = ParsedInput
158-
member _.ParseErrors = ParseErrors
158+
member _.ParseDiagnostics = ParseDiagnostics
159159

160160
member val IsSignatureFile = FileName |> isSignatureFile
161161

src/Compiler/Service/TransparentCompiler.fs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,9 @@ type internal TransparentCompiler
12511251

12521252
let sink = TcResultsSinkImpl(tcGlobals, file.SourceText)
12531253

1254-
let hadParseErrors = not (Array.isEmpty file.ParseErrors)
1254+
let hadParseErrors =
1255+
file.ParseDiagnostics
1256+
|> Array.exists (snd >> (=) FSharpDiagnosticSeverity.Error)
12551257

12561258
let input, moduleNamesDict =
12571259
DeduplicateParsedInputModuleName prevTcInfo.moduleNamesDict input
@@ -1448,7 +1450,7 @@ type internal TransparentCompiler
14481450
tcConfig.diagnosticsOptions,
14491451
false,
14501452
file.FileName,
1451-
parsedFile.ParseErrors,
1453+
parsedFile.ParseDiagnostics,
14521454
suggestNamesForErrors,
14531455
tcConfig.flatErrors,
14541456
None

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,3 +960,54 @@ let ``Background compiler and Transparent compiler return the same options`` ()
960960
Assert.Equal<string list>(backgroundSnapshot.OtherOptions, transparentSnapshot.OtherOptions)
961961
Assert.Equal<ProjectSnapshot.ReferenceOnDisk list>(backgroundSnapshot.ReferencesOnDisk, transparentSnapshot.ReferencesOnDisk)
962962
}
963+
964+
[<Theory>]
965+
[<InlineData(false)>]
966+
[<InlineData(true)>]
967+
let ``Unused warning should still produce after parse warning`` useTransparentCompiler =
968+
969+
// There should be parse warning because of the space in the file name:
970+
// warning FS0221: The declarations in this file will be placed in an implicit module 'As 01' based on the file name 'As 01.fs'.
971+
// 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.
972+
973+
let project =
974+
{ SyntheticProject.Create(
975+
{ sourceFile "As 01" [] with
976+
Source = """
977+
do
978+
let _ as b = ()
979+
()
980+
981+
// For more information see https://aka.ms/fsharp-console-apps
982+
printfn "Hello from F#"
983+
"""
984+
SignatureFile = No
985+
986+
}) with
987+
AutoAddModules = false
988+
OtherOptions = [
989+
"--target:exe"
990+
"--warn:3"
991+
"--warnon:1182"
992+
"--warnaserror:3239"
993+
"--noframework"
994+
]
995+
}
996+
997+
let expectTwoWarnings (_parseResult:FSharpParseFileResults, checkAnswer: FSharpCheckFileAnswer) (_, _) =
998+
match checkAnswer with
999+
| FSharpCheckFileAnswer.Aborted -> failwith "Should not have aborted"
1000+
| FSharpCheckFileAnswer.Succeeded checkResults ->
1001+
let hasParseWarning =
1002+
checkResults.Diagnostics
1003+
|> Array.exists (fun diag -> diag.Severity = FSharpDiagnosticSeverity.Warning && diag.ErrorNumber = 221)
1004+
Assert.True(hasParseWarning, "Expected parse warning FS0221")
1005+
1006+
let hasCheckWarning =
1007+
checkResults.Diagnostics
1008+
|> Array.exists (fun diag -> diag.Severity = FSharpDiagnosticSeverity.Warning && diag.ErrorNumber = 1182)
1009+
Assert.True(hasCheckWarning, "Expected post inference warning FS1182")
1010+
1011+
ProjectWorkflowBuilder(project, useTransparentCompiler = useTransparentCompiler) {
1012+
checkFile "As 01" expectTwoWarnings
1013+
}

0 commit comments

Comments
 (0)