Skip to content

(minimal, patching-over fix) async rules crash under the TransparentCompiler#862

Open
michaelglass wants to merge 1 commit into
fsprojects:masterfrom
michaelglass:fix/transparentcompiler-projectoptions
Open

(minimal, patching-over fix) async rules crash under the TransparentCompiler#862
michaelglass wants to merge 1 commit into
fsprojects:masterfrom
michaelglass:fix/transparentcompiler-projectoptions

Conversation

@michaelglass

@michaelglass michaelglass commented Jul 3, 2026

Copy link
Copy Markdown

SIMPLER of two alternative fixes for the same crash — the COMPLETE alternative is #863, which preserves the rules' behavior under the TransparentCompiler at the cost of a small public-API addition. Mutually exclusive; pick one.

When this happens

If you run FSharpLint as a library — the lintParsedFile / lintParsedSource API, passing your own ProjectCheckResults — and those results come from an FSharpChecker created with useTransparentCompiler = true, linting aborts on otherwise-valid files with an internal error. The trigger is the async/library-heuristic rules: AsynchronousFunctionNames, SimpleAsyncComplementaryHelpers, and NoAsyncRunSynchronouslyInLibrary (the first and last are on by default).

Concretely: in my project FsHotWatch I use FSharpLint as a library (not the CLI tool), reusing warm FCS check results to re-lint files on save. When I switched the underlying FSharpChecker to the TransparentCompiler, valid files started failing to lint with an internal error.

Why

Those rules need the project file name. They get it through the two-phase ProjectOptions lazy (added in 91fd00b0), which reads FSharpProjectContext.ProjectOptions — a getter that throws by design under the TransparentCompiler. Forcing the lazy then raises, and FSharpLint reports the whole file as failed.

Fix

Wrap the single ProjectOptions lazy in try … with _ -> None, so those rules fall back to their non-project heuristics instead of failing the file. One change at the source of the shared lazy, so every rule that uses it benefits.

Test

TestApi.fs regression: lints results produced by FSharpChecker.Create(useTransparentCompiler = true) and asserts no internal failure — it reproduces the crash without the fix and passes with it.

if it wasn't obvious from the tone of the PR: this work was done with the extensive help with AI, and then eyeballed / confirmed by a fleshy human being

…er check results

FSharpProjectContext.get_ProjectOptions() throws by design when the check
results come from FCS's TransparentCompiler (as used by some analyzer hosts).
Rules that force the two-phase ProjectOptions lazy (the library heuristics in
AsynchronousFunctionNames, SimpleAsyncComplementaryHelpers,
NoAsyncRunSynchronouslyInLibrary) then abort linting of the whole file with an
internal error. Wrap the single lazy construction site in try/with -> None so
those heuristics fall back gracefully instead of failing the file.

Regression: TestApi lints TransparentCompiler-produced parse+check results and
asserts no ProjectProgress.Failed is reported.
@michaelglass michaelglass changed the title fix(Core): async rules crash under the TransparentCompiler — SIMPLER fix (degrade) (minimal, patching-over fix) async rules crash under the TransparentCompiler Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant