Skip to content

Commit 07fbf54

Browse files
Copilotabonie
andcommitted
Fix test for Windows paths and add test for errors in loaded files
Co-authored-by: abonie <20281641+abonie@users.noreply.github.com>
1 parent 665f272 commit 07fbf54

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

src/Compiler/Interactive/fsi.fs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2500,7 +2500,18 @@ type internal FsiDynamicCompiler
25002500
let isIncrementalFragment = true
25012501

25022502
let istate, tcEnvAtEndOfLastInput, declaredImpls =
2503-
ProcessInputs(ctok, diagnosticsLogger, istate, [ input ], showTypes, isIncrementalFragment, isInteractiveItExpr, prefix, m, false)
2503+
ProcessInputs(
2504+
ctok,
2505+
diagnosticsLogger,
2506+
istate,
2507+
[ input ],
2508+
showTypes,
2509+
isIncrementalFragment,
2510+
isInteractiveItExpr,
2511+
prefix,
2512+
m,
2513+
false
2514+
)
25042515

25052516
let tcState = istate.tcState
25062517

tests/FSharp.Compiler.ComponentTests/Scripting/TypeCheckOnlyTests.fs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module FSharp.Compiler.ComponentTests.Scripting.TypeCheckOnlyTests
22

3+
open System
34
open System.IO
45
open Xunit
56
open FSharp.Test
@@ -51,19 +52,50 @@ let x = 21+21
5152
let ``typecheck-only flag catches type errors in scripts with #load``() =
5253
let tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())
5354
Directory.CreateDirectory(tempDir) |> ignore
55+
let originalDir = Environment.CurrentDirectory
5456

5557
try
58+
Environment.CurrentDirectory <- tempDir
5659
let domainPath = Path.Combine(tempDir, "Domain.fsx")
5760
let mainPath = Path.Combine(tempDir, "A.fsx")
5861

5962
File.WriteAllText(domainPath, "type T = { Field: string }\nprintfn \"D\"")
60-
File.WriteAllText(mainPath, sprintf "#load \"%s\"\nopen Domain\nlet y = { Field = 1 }\nprintfn \"A\"" domainPath)
63+
File.WriteAllText(mainPath, "#load \"Domain.fsx\"\nopen Domain\nlet y = { Field = 1 }\nprintfn \"A\"")
6164

6265
FsxFromPath mainPath
6366
|> withOptions ["--typecheck-only"]
6467
|> runFsi
6568
|> shouldFail
6669
|> withStdErrContains "This expression was expected to have type"
6770
finally
68-
if Directory.Exists(tempDir) then
69-
Directory.Delete(tempDir, true)
71+
try
72+
Environment.CurrentDirectory <- originalDir
73+
if Directory.Exists(tempDir) then
74+
Directory.Delete(tempDir, true)
75+
with _ -> ()
76+
77+
[<Fact>]
78+
let ``typecheck-only flag catches type errors in loaded file``() =
79+
let tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())
80+
Directory.CreateDirectory(tempDir) |> ignore
81+
let originalDir = Environment.CurrentDirectory
82+
83+
try
84+
Environment.CurrentDirectory <- tempDir
85+
let domainPath = Path.Combine(tempDir, "Domain.fsx")
86+
let mainPath = Path.Combine(tempDir, "A.fsx")
87+
88+
File.WriteAllText(domainPath, "type T = { Field: string }\nlet x: int = \"error\"\nprintfn \"D\"")
89+
File.WriteAllText(mainPath, "#load \"Domain.fsx\"\nopen Domain\nlet y = { Field = \"ok\" }\nprintfn \"A\"")
90+
91+
FsxFromPath mainPath
92+
|> withOptions ["--typecheck-only"]
93+
|> runFsi
94+
|> shouldFail
95+
|> withStdErrContains "This expression was expected to have type"
96+
finally
97+
try
98+
Environment.CurrentDirectory <- originalDir
99+
if Directory.Exists(tempDir) then
100+
Directory.Delete(tempDir, true)
101+
with _ -> ()

0 commit comments

Comments
 (0)