Skip to content

Commit 9d2797a

Browse files
authored
[WIP] Support --typecheck-only for fsi run (just typecheck, no execution) (#18687)
1 parent b21284f commit 9d2797a

26 files changed

+145
-4
lines changed

docs/release-notes/.FSharp.Compiler.Service/10.0.100.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### Added
22
* Add opt-in warning attribute not valid for union case with fields [PR #18532](https://github.com/dotnet/fsharp/pull/18532))
33
* Add support for `when 'T : Enum` library-only static optimization constraint. ([PR #18546](https://github.com/dotnet/fsharp/pull/18546))
4+
* Add `--typecheck-only` flag support for F# Interactive (FSI) scripts to type-check without execution. ([Issue #18686](https://github.com/dotnet/fsharp/issues/18686))
45

56
### Fixed
67

src/Compiler/Driver/CompilerOptions.fs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,13 @@ let advancedFlagsFsi tcConfigB =
13081308
None,
13091309
Some(FSComp.SR.optsClearResultsCache ())
13101310
)
1311+
CompilerOption(
1312+
"typecheck-only",
1313+
tagNone,
1314+
OptionUnit(fun () -> tcConfigB.typeCheckOnly <- true),
1315+
None,
1316+
Some(FSComp.SR.optsTypecheckOnly ())
1317+
)
13111318
]
13121319

13131320
let advancedFlagsFsc tcConfigB =

src/Compiler/FSComp.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ optsVersion,"Display compiler version banner and exit"
902902
optsResponseFile,"Read response file for more options"
903903
optsCodepage,"Specify the codepage used to read source files"
904904
optsClearResultsCache,"Clear the package manager results cache"
905+
optsTypecheckOnly,"Perform type checking only, do not execute code"
905906
optsUtf8output,"Output messages in UTF-8 encoding"
906907
optsFullpaths,"Output messages with fully qualified paths"
907908
optsLib,"Specify a directory for the include path which is used to resolve source files and assemblies (Short form: -I)"

src/Compiler/Interactive/fsi.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,11 @@ type internal FsiDynamicCompiler
22172217
inputs
22182218
))
22192219

2220+
// typeCheckOnly either reports all errors found so far or exits with 0 - it stops processing the script
2221+
if tcConfig.typeCheckOnly then
2222+
diagnosticsLogger.AbortOnError(fsiConsoleOutput)
2223+
raise StopProcessing
2224+
22202225
let codegenResults, optEnv, fragName =
22212226
ProcessTypedImpl(
22222227
diagnosticsLogger,
@@ -4763,6 +4768,7 @@ type FsiEvaluationSession
47634768
let userRes =
47644769
match res with
47654770
| Choice1Of2 r -> Choice1Of2 r
4771+
| Choice2Of2 None when errorInfos.Length = 0 && tcConfigB.typeCheckOnly -> Choice1Of2 None
47664772
| Choice2Of2 None ->
47674773
Choice2Of2(FsiCompilationException(FSIstrings.SR.fsiOperationCouldNotBeCompleted (), Some errorInfos) :> exn)
47684774
| Choice2Of2(Some userExn) -> Choice2Of2 userExn

src/Compiler/xlf/FSComp.txt.cs.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.de.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.es.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.fr.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.it.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.ja.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)