-
Notifications
You must be signed in to change notification settings - Fork 824
[WIP] Support --typecheck-only for fsi run (just typecheck, no execution) #18687
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
base: main
Are you sure you want to change the base?
Changes from all commits
4995602
89b69aa
a8db5c6
7ea403c
bd5aa05
9836e52
e276875
d3d4ea0
66ba4f3
312cdbd
7d5cba7
0140ab0
f43c85a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2217,6 +2217,11 @@ type internal FsiDynamicCompiler | |
inputs | ||
)) | ||
|
||
// typeCheckOnly either reports all errors found so far or exits with 0 - it stops processing the script | ||
if tcConfig.typeCheckOnly then | ||
diagnosticsLogger.AbortOnError(fsiConsoleOutput) | ||
raise StopProcessing | ||
|
||
let codegenResults, optEnv, fragName = | ||
ProcessTypedImpl( | ||
diagnosticsLogger, | ||
|
@@ -4763,6 +4768,7 @@ type FsiEvaluationSession | |
let userRes = | ||
match res with | ||
| Choice1Of2 r -> Choice1Of2 r | ||
| Choice2Of2 None when errorInfos.Length = 0 && tcConfigB.typeCheckOnly -> Choice1Of2 None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because of this change, line numbers after ilxgen for closures have shifted and therefore slightly changed ilverify baseline. Read this repo docs for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated ILVerify baselines to fix line number shifts caused by the code additions in fsi.fs. Updated line references from 3494→3495, 2225→2226, and 4446→4447 across all FSharp.Compiler.Service baseline files (Debug/Release, net9.0/netstandard2.0). Commit f43c85a addresses this issue. |
||
| Choice2Of2 None -> | ||
Choice2Of2(FsiCompilationException(FSIstrings.SR.fsiOperationCouldNotBeCompleted (), Some errorInfos) :> exn) | ||
| Choice2Of2(Some userExn) -> Choice2Of2 userExn | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module FSharp.Compiler.ComponentTests.Scripting.TypeCheckOnlyTests | ||
|
||
open Xunit | ||
open FSharp.Test | ||
open FSharp.Test.Compiler | ||
|
||
[<Fact>] | ||
let ``typecheck-only flag works for valid script``() = | ||
Fsx """ | ||
let x = 42 | ||
printfn "This should not execute" | ||
exit 999 // this would have crashed if really running | ||
""" | ||
|> withOptions ["--typecheck-only"] | ||
|> runFsi | ||
|> shouldSucceed | ||
|
||
[<Fact>] | ||
let ``typecheck-only flag catches type errors``() = | ||
Fsx """ | ||
let x: int = "string" // Type error | ||
""" | ||
|> withOptions ["--typecheck-only"] | ||
|> runFsi | ||
|> shouldFail | ||
|> withStdErrContains """This expression was expected to have type""" | ||
|
||
[<Fact>] | ||
let ``typecheck-only flag prevents execution side effects``() = | ||
Fsx """ | ||
printfn "MyCrazyString" | ||
let x = 42 | ||
""" | ||
|> withOptions ["--typecheck-only"] | ||
|> runFsi | ||
|> shouldSucceed | ||
|> verifyNotInOutput "MyCrazyString" | ||
|
||
[<Fact>] | ||
let ``script executes without typecheck-only flag``() = | ||
Fsx """ | ||
let x = 21+21 | ||
""" | ||
|> withOptions ["--nologo"] | ||
|> runFsi | ||
|> shouldSucceed | ||
|> verifyOutputContains [|"val x: int = 42"|] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This option is now available for help, hence the following 4 tests are failing:
CompilerOptions\fsi\help (-?-40) -- failed
CompilerOptions\fsi\help (--help-40) -- failed
CompilerOptions\fsi\help (/?-40) -- failed
CompilerOptions\fsi\help (-? --nologo-40) -- failed
They are part of the FsharpQa suite.
This can help you, the new lines are added between clearResultsCache and exec options:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated help baselines to include the new --typecheck-only option. The baseline files help40.437.1033.bsl and help40-nologo.437.1033.bsl now correctly show the new option between clearResultsCache and exec options as expected. Commit f43c85a addresses this issue.