refactor(all): add [<return: Struct>] to partial active patterns#4658
Open
dbrattli wants to merge 1 commit into
Open
refactor(all): add [<return: Struct>] to partial active patterns#4658dbrattli wants to merge 1 commit into
dbrattli wants to merge 1 commit into
Conversation
Convert 73 partial active patterns across the compiler transforms to struct-returning (ValueOption) form, resolving all open IONIDE-009 code scanning alerts in src/Fable.Transforms. Only return-position values were changed to ValueSome/ValueNone; nested option match patterns and inner option plumbing are left intact (bridged with explicit matches or ValueOption.ofOption where a helper produced a plain option). The (|CustomOp|_|) pattern is also invoked as a plain function in Beam/Replacements.fs; those two call sites are adapted to the new voption result. Fable.AST/Fable.fs is intentionally not touched: changing a public AST active pattern's return type is a binary-breaking change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Python Type Checking Results (Pyright)
Excluded files with errors (4 files)These files have known type errors and are excluded from CI. Remove from
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves all open IONIDE-009 code scanning alerts ("Consider adding
[<return: Struct>]to partial active pattern") insrc/Fable.Transforms. Converts 73 partial active patterns to struct-returning (ValueOption) form across 9 files.Struct active patterns avoid the heap allocation of
Optionon every pattern match, which matters in the hot compiler paths these patterns sit on (replacements, AST transforms).What changed
For each flagged pattern: added
[<return: Struct>]and changed only the return-position values toValueSome/ValueNone. Nested option match patterns (e.g.{ FieldType = Some t }), inner option plumbing, and cross-pattern/recursive calls in pattern position were left untouched. Where a pattern's result came from a helper returning a plainoption, it is bridged with an explicit match orValueOption.ofOption.FSharp2Fable.Util.fsReplacements.Util.fsTransforms.Util.fsReplacements.fsGlobal/Prelude.fsFable2Babel.fsGlobal/Naming.fsFableTransforms.fsPython/Replacements.fs(|CustomOp|_|)is also invoked as a plain function (not in pattern position) at two sites inBeam/Replacements.fs; those matches are adapted to the newvoptionresult.Intentionally skipped
Tags.(|Contains|_|)atsrc/Fable.AST/Fable.fs:12(1 alert) is not changed —Fable.ASTis the public AST and switching an active pattern's return type fromOptiontoValueOptionis a binary-breaking change requiring a major version bump (perAGENTS.md).Verification
dotnet build src/Fable.Cli/Fable.Cli.fsproj -c Release(covers all targets — JS/TS, Python, Rust, Dart, BEAM) succeeds with 0 warnings, 0 errors.🤖 Generated with Claude Code