Skip to content

Commit f11cde3

Browse files
Add more tests and improve fix
1 parent 527890f commit f11cde3

File tree

13 files changed

+73
-47
lines changed

13 files changed

+73
-47
lines changed

src/fsharp/CompileOps.fs

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4976,38 +4976,32 @@ module private ScriptPreprocessClosure =
49764976
match closureDirective with
49774977
| ClosedSourceFile _ as csf -> [csf]
49784978
| SourceFile(filename,m,source) ->
4979-
let filename = FileSystem.GetFullPathShim(filename)
4980-
if observedSources.HaveSeen(filename) then []
4981-
else
4982-
observedSources.SetSeen(filename)
4983-
4984-
let errors = ref []
4985-
let warnings = ref []
4986-
let errorLogger =
4987-
{ new ErrorLogger("FindClosure") with
4988-
member x.ErrorSinkImpl(e) = errors := e :: !errors
4989-
member x.WarnSinkImpl(e) = warnings := e :: !warnings
4990-
member x.ErrorCount = (!errors).Length }
4991-
4992-
use unwindEL = PushErrorLoggerPhaseUntilUnwind (fun _ -> errorLogger)
4993-
let pathOfMetaCommandSource = Path.GetDirectoryName(filename)
4994-
match ParseScriptText(filename,source,!tcConfig,codeContext,lexResourceManager,errorLogger) with
4995-
| Some(input) ->
4996-
let tcConfigResult, noWarns = ApplyMetaCommandsFromInputToTcConfigAndGatherNoWarn !tcConfig (input,pathOfMetaCommandSource)
4997-
tcConfig := tcConfigResult
4979+
let errors = ref []
4980+
let warnings = ref []
4981+
let errorLogger =
4982+
{ new ErrorLogger("FindClosure") with
4983+
member x.ErrorSinkImpl(e) = errors := e :: !errors
4984+
member x.WarnSinkImpl(e) = warnings := e :: !warnings
4985+
member x.ErrorCount = (!errors).Length }
4986+
4987+
use unwindEL = PushErrorLoggerPhaseUntilUnwind (fun _ -> errorLogger)
4988+
let pathOfMetaCommandSource = Path.GetDirectoryName(filename)
4989+
match ParseScriptText(filename,source,!tcConfig,codeContext,lexResourceManager,errorLogger) with
4990+
| Some(input) ->
4991+
let tcConfigResult, noWarns = ApplyMetaCommandsFromInputToTcConfigAndGatherNoWarn !tcConfig (input,pathOfMetaCommandSource)
4992+
tcConfig := tcConfigResult
49984993

4999-
let AddFileIfNotSeen(m,filename) =
5000-
if observedSources.HaveSeen(filename) then []
5001-
else
5002-
if IsScript(filename) then SourceFileOfFilename(filename,m,tcConfigResult.inputCodePage)
5003-
else
5004-
observedSources.SetSeen(filename)
5005-
[ClosedSourceFile(filename,m,None,[],[],[])] // Don't traverse into .fs leafs.
4994+
let AddFileIfNotSeen(m,filename) =
4995+
if observedSources.HaveSeen(filename) then []
4996+
else
4997+
observedSources.SetSeen(filename)
4998+
if IsScript(filename) then SourceFileOfFilename(filename,m,tcConfigResult.inputCodePage)
4999+
else [ClosedSourceFile(filename,m,None,[],[],[])] // Don't traverse into .fs leafs.
50065000

5007-
let loadedSources = (!tcConfig).GetAvailableLoadedSources() |> List.rev |> List.map AddFileIfNotSeen |> List.concat
5008-
(loadedSources |> List.map FindClosure |> List.concat)
5009-
@ [ClosedSourceFile(filename,m,Some(input),!errors,!warnings,!noWarns)]
5010-
| None -> [ClosedSourceFile(filename,m,None,!errors,!warnings,[])]
5001+
let loadedSources = (!tcConfig).GetAvailableLoadedSources() |> List.map AddFileIfNotSeen |> List.concat
5002+
(loadedSources |> List.map FindClosure |> List.concat)
5003+
@ [ClosedSourceFile(filename,m,Some(input),!errors,!warnings,!noWarns)]
5004+
| None -> [ClosedSourceFile(filename,m,None,!errors,!warnings,[])]
50115005

50125006
closureDirectives |> List.map FindClosure |> List.concat, !tcConfig
50135007

@@ -5025,7 +5019,7 @@ module private ScriptPreprocessClosure =
50255019
let sourceFiles = ref []
50265020
let sourceInputs = ref []
50275021
let globalNoWarns = ref []
5028-
for directive in closureDirectives do
5022+
for directive in List.rev closureDirectives do
50295023
match directive with
50305024
| ClosedSourceFile(filename,m,input,_,_,noWarns) ->
50315025
let filename = FileSystem.GetFullPathShim(filename)
@@ -5068,8 +5062,8 @@ module private ScriptPreprocessClosure =
50685062
let rootWarnings = rootWarnings |> List.filter isRootRange
50695063

50705064
let result : LoadClosure =
5071-
{ SourceFiles = List.groupByFirst !sourceFiles |> List.rev
5072-
References = List.groupByFirst references |> List.rev
5065+
{ SourceFiles = List.groupByFirst !sourceFiles
5066+
References = List.groupByFirst references
50735067
UnresolvedReferences = unresolvedReferences
50745068
Inputs = !sourceInputs
50755069
NoWarns = List.groupByFirst !globalNoWarns

tests/service/ProjectOptionsTests.fs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,20 @@ let ``Project file parsing -- report files``() =
420420

421421
[<Test>]
422422
let ``Test ProjectFileNames order for GetProjectOptionsFromScript`` () = // See #594
423-
let scriptPath = __SOURCE_DIRECTORY__ + @"/data/ScriptProject/Main.fsx"
424-
let scriptSource = File.ReadAllText scriptPath
425-
let projOpts =
426-
checker.GetProjectOptionsFromScript(scriptPath, scriptSource)
427-
|> Async.RunSynchronously
428-
projOpts.ProjectFileNames
429-
|> Array.map Path.GetFileNameWithoutExtension
430-
|> (=) [|"BaseLib"; "Lib1"; "Lib2"; "Main"|]
431-
|> shouldEqual true
423+
let test scriptName expected =
424+
let scriptPath = __SOURCE_DIRECTORY__ + @"/data/ScriptProject/" + scriptName + ".fsx"
425+
let scriptSource = File.ReadAllText scriptPath
426+
let projOpts =
427+
checker.GetProjectOptionsFromScript(scriptPath, scriptSource)
428+
|> Async.RunSynchronously
429+
projOpts.ProjectFileNames
430+
|> Array.map Path.GetFileNameWithoutExtension
431+
|> (=) expected
432+
|> shouldEqual true
433+
test "Main1" [|"BaseLib1"; "Lib1"; "Lib2"; "Main1"|]
434+
test "Main2" [|"BaseLib1"; "Lib1"; "Lib2"; "Lib3"; "Main2"|]
435+
test "Main3" [|"Lib3"; "Lib4"; "Main3"|]
436+
test "Main4" [|"BaseLib2"; "Lib5"; "BaseLib1"; "Lib1"; "Lib2"; "Main4"|]
432437

433438
#endif
434439

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module BaseLib
1+
module BaseLib1
22

33
let add2 x = x + 2
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module BaseLib2
2+
3+
let add10 x = x + 10
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#load "BaseLib.fs"
2-
let add3 = BaseLib.add2 >> ((+) 1)
1+
#load "BaseLib1.fs"
2+
let add3 = BaseLib1.add2 >> ((+) 1)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#load "BaseLib.fs"
2-
let add4 = BaseLib.add2 >> ((+) 2)
1+
#load "BaseLib1.fs"
2+
let add4 = BaseLib1.add2 >> ((+) 2)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Lib3
2+
3+
let add6 = ((+) 6)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Lib4
2+
3+
let add8 = ((+) 8)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#load "BaseLib2.fs"
2+
let add12 = BaseLib2.add10 >> ((+) 2)
File renamed without changes.

0 commit comments

Comments
 (0)