Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incremental builder: fix exception when source files list is empty #16314

Merged
merged 2 commits into from
Nov 21, 2023
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
10 changes: 2 additions & 8 deletions src/Compiler/Service/IncrementalBuild.fs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ module IncrementalBuilderHelpers =
}

/// Finish up the typechecking to produce outputs for the rest of the compilation process
let FinalizeTypeCheckTask (tcConfig: TcConfig) tcGlobals partialCheck assemblyName outfile (initialErrors: SingleFileDiagnostics) (boundModels: GraphNode<BoundModel> seq) =
let FinalizeTypeCheckTask (tcConfig: TcConfig) tcGlobals partialCheck assemblyName outfile (boundModels: GraphNode<BoundModel> seq) =
node {
let diagnosticsLogger = CompilationDiagnosticLogger("FinalizeTypeCheckTask", tcConfig.diagnosticsOptions)
use _ = new CompilationGlobalsScope(diagnosticsLogger, BuildPhase.TypeCheck)
Expand Down Expand Up @@ -820,7 +820,6 @@ module IncrementalBuilderHelpers =
let diagnostics = [
diagnosticsLogger.GetDiagnostics()
yield! partialDiagnostics |> Seq.rev
initialErrors
]

let! finalBoundModelWithErrors = finalBoundModel.Finish(diagnostics, Some topAttrs)
Expand Down Expand Up @@ -927,7 +926,6 @@ type IncrementalBuilderState =
{
slots: Slot list
stampedReferencedAssemblies: ImmutableArray<DateTime>
initialBoundModel: GraphNode<BoundModel>
finalizedBoundModel: GraphNode<(ILAssemblyRef * ProjectAssemblyDataResult * CheckedImplFile list option * BoundModel) * DateTime>
}
member this.stampedFileNames = this.slots |> List.map (fun s -> s.Stamp)
Expand All @@ -949,15 +947,13 @@ module IncrementalBuilderStateHelpers =
let createFinalizeBoundModelGraphNode (initialState: IncrementalBuilderInitialState) (boundModels: GraphNode<BoundModel> seq) =
GraphNode(node {
use _ = Activity.start "GetCheckResultsAndImplementationsForProject" [|Activity.Tags.project, initialState.outfile|]
let! initialErrors = initialState.initialBoundModel.Diagnostics.GetOrComputeValue()
let! result =
FinalizeTypeCheckTask
initialState.tcConfig
initialState.tcGlobals
initialState.enablePartialTypeChecking
initialState.assemblyName
initialState.outfile
initialErrors
boundModels
return result, DateTime.UtcNow
})
Expand Down Expand Up @@ -1060,11 +1056,10 @@ type IncrementalBuilderState with
let boundModels =
syntaxTrees
|> Seq.scan createBoundModelGraphNode initialBoundModel
|> Seq.skip 1

let slots =
[
for model, syntaxTree, hasSignature in Seq.zip3 boundModels syntaxTrees hasSignature do
for model, syntaxTree, hasSignature in Seq.zip3 (boundModels |> Seq.skip 1) syntaxTrees hasSignature do
{
HasSignature = hasSignature
Stamp = DateTime.MinValue
Expand All @@ -1079,7 +1074,6 @@ type IncrementalBuilderState with
{
slots = slots
stampedReferencedAssemblies = ImmutableArray.init referencedAssemblies.Length (fun _ -> DateTime.MinValue)
initialBoundModel = initialBoundModel
finalizedBoundModel = createFinalizeBoundModelGraphNode initialState boundModels
}
let state = computeStampedReferencedAssemblies initialState state false cache
Expand Down
15 changes: 15 additions & 0 deletions tests/service/ProjectAnalysisTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5751,3 +5751,18 @@ let ``References from #r nuget are included in script project options`` () =
|> Seq.distinct
printfn "%s" (assemblyNames |> String.concat "\n")
assemblyNames |> should contain "Dapper.dll"

module internal EmptyProject =
let base2 = tryCreateTemporaryFileName ()
let dllName = Path.ChangeExtension(base2, ".dll")
let projFileName = Path.ChangeExtension(base2, ".fsproj")

let fileNames = []
let args = mkProjectCommandLineArgs (dllName, fileNames)
let options = checker.GetProjectOptionsFromCommandLineArgs (projFileName, args)

[<Test>]
let ``Empty source list produces error FS0207`` () =
let results = checker.ParseAndCheckProject(EmptyProject.options) |> Async.RunImmediate
results.Diagnostics.Length |> shouldEqual 1
results.Diagnostics[0].ErrorNumber |> shouldEqual 207
Loading