Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Copilot wants to merge6 commits intomain
base:main
Choose a base branch
Loading
fromcopilot/fix-18686

Conversation

Copilot
Copy link
Contributor

Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.

Original issue description:

Instructions for Adding--typecheck-only Support to F# Interactive Scripts

Problem Statement

The--typecheck-only flag already exists for F# project compilation but is not supported for.fsx script files in F# Interactive (FSI). Currently, there's no way to type-check scripts without executing them through the FSI command line. This feature would allow developers to validate script syntax and types without running potentially side-effect-producing code.

Implementation Steps

1. Add Command Line Option

Add the--typecheck-only option to the FSI command line parser. Insert a newCompilerOption in the advanced options section:

CompilerOption("typecheck-only","", OptionUnit(fun()-> tcConfigB.typeCheckOnly<-true), None, Some("Type-check only, don't execute"))

This should be added alongside other advanced options likeexec,gui,quiet, etc.

2. Modify ProcessInputs Function

The core implementation goes in theProcessInputs function. In2 , add a check afterCheckClosedInputSet and beforeProcessTypedImpl:

lettcState,topCustomAttrs,declaredImpls,tcEnvAtEndOfLastInput=    lock tcLockObject(fun _->        CheckClosedInputSet(            ctok,(fun()-> diagnosticsLogger.CheckForRealErrorsIgnoringWarnings),            tcConfig,            tcImports,            tcGlobals,            Some prefixPath,            tcState,            eagerFormat,            inputs))// Add this check after CheckClosedInputSetif tcConfig.typeCheckOnlythen    raise StopProcessingletcodegenResults,optEnv,fragName=    ProcessTypedImpl(...)

3. Exception Handling

TheStopProcessing exception is already handled . This infrastructure will properly catch the exception and stop processing without executing the script.

Testing Implementation

Test Location and Structure

All tests should be added to theFSharp.Compiler.ComponentTests project.

Create a new test file:
tests/FSharp.Compiler.ComponentTests/Scripting/TypeCheckOnlyTests.fs

Test Implementation

moduleFSharp.Compiler.ComponentTests.Scripting.TypeCheckOnlyTestsopenXunitopenFSharp.TestopenFSharp.Test.Compiler[<Fact>]let``typecheck-only flag works for valid script``()=    Fsx"""let x = 42printfn "This should not execute""""|> withOptions["--typecheck-only"]|> compile|> shouldSucceed[<Fact>]let``typecheck-only flag catches type errors``()=    Fsx"""let x: int = "string"  // Type error"""|> withOptions["--typecheck-only"]|> compile|> shouldFail|> withDiagnostics[(Error1, Line2, Col14, Line2, Col22,"This expression was expected to have type\n    'int'\nbut here has type\n    'string'")][<Fact>]let``typecheck-only flag prevents execution side effects``()=    Fsx"""System.IO.File.WriteAllText("test-file.txt", "should not be created")let x = 42"""|> withOptions["--typecheck-only"]|> compile|> shouldSucceed// Verify file was not created (test would need additional verification logic)

Project File Update

Add the new test file:

<CompileInclude="Scripting/TypeCheckOnlyTests.fs" />

Test Utilities

The ComponentTests project references Test utilities , which provides testing utilities likeFsx,withOptions,compile,shouldSucceed, andshouldFail.

Key Implementation Notes

  1. The--typecheck-only flag already exists in the core F# compiler configuration (TcConfigBuilder), so you're primarily adding FSI-specific handling.

  2. TheProcessInputs function is the correct location for this check because it occurs after parsing and type-checking but before code generation and execution.

  3. TheStopProcessing exception mechanism is already established in FSI for handling compilation-stopping conditions.

  4. All new tests should use the ComponentTests project following modern F# testing practices.

This implementation will allow users to runfsi --typecheck-only script.fsx to validate script correctness without execution.

Fixes#18686.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn moreCopilot coding agent tips in the docs.

@T-Gro
Copy link
Member

@copilot try again pls

@github-actionsGitHub Actions
Copy link
Contributor

github-actionsbot commentedJun 12, 2025
edited
Loading

❗ Release notes required

@copilot,

Caution

No release notes found for the changed paths (see table below).

Please make sure to add an entry with an informative description of the change as well as link to this pull request, issue and language suggestion if applicable. Release notes for this repository are based onKeep A Changelog format.

The following format is recommended for this repository:

* <Informative description>. ([PR #XXXXX](https://github.com/dotnet/fsharp/pull/XXXXX))

See examples in the files, listed in the table below or in th full documentation athttps://fsharp.github.io/fsharp-compiler-docs/release-notes/About.html.

If you believe that release notes are not necessary for this PR, please addNO_RELEASE_NOTES label to the pull request.

You can open this PR in browser to add release notes:open in github.dev

Change pathRelease notes pathDescription
src/Compilerdocs/release-notes/.FSharp.Compiler.Service/10.0.100.mdNo release notes found or release notes format is not correct

Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
@CopilotCopilot SWE Agent
Copy link
ContributorAuthor

CopilotAI commentedJun 12, 2025
edited
Loading

@copilot try again pls

I've implemented the --typecheck-only support for FSI as requested. The implementation includes:

  1. Added the --typecheck-only command line option to FSI advanced options
  2. Added the logic to stop processing after type checking when the flag is used
  3. Created comprehensive tests for the functionality

The changes are minimal and surgical, following the existing patterns in the codebase. Commita8db5c6 contains the complete implementation.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • s8mvsblobprodcus38.vsblob.vsassets.io
    • Triggering command:/usr/share/dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/fsharp/fsharp/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/fsharp/fsharp/artifacts/toolset/10.0.0-beta.25271.2.txt (dns block)
    • Triggering command:dotnet build tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj --verbosity quiet (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Copilot finished work on behalf ofT-GroJune 12, 2025 12:21
@T-Gro
Copy link
Member

@copilot :

In the side effect test: rather than generating a file as the side effect which needs cleanup, just have the script print a string to the console. And use verifyOutput "MyCrazyString"

You will need to add a not contains version though.
perhaps:
VerifyNotInOutput "MyCrazyString"

…effectsCo-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
@CopilotCopilot SWE Agent
Copy link
ContributorAuthor

CopilotAI commentedJun 16, 2025
edited
Loading

@copilot :

In the side effect test: rather than generating a file as the side effect which needs cleanup, just have the script print a string to the console. And use verifyOutput "MyCrazyString"
...

Updated the tests to use console output withprintfn "MyCrazyString" instead of file creation. Added theVerifyNotInOutput function for negative verification and updated the tests to useverifyOutput "MyCrazyString" for the positive case andVerifyNotInOutput "MyCrazyString" for the negative case. Commitbd5aa05 contains these changes.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • s8mvsblobprodcus38.vsblob.vsassets.io
    • Triggering command:dotnet test tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj --filter DisplayName~TypeCheckOnlyTests --verbosity normal (dns block)
    • Triggering command:dotnet build tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj --verbosity quiet (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf ofT-GroJune 16, 2025 08:39
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Labels
None yet
Projects
Status: New
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Support --typecheck-only for fsi run (just typecheck, no execution)
2 participants
@Copilot@T-Gro

[8]ページ先頭

©2009-2025 Movatter.jp