Skip to content

refactor(all): mark enum-like DUs [<Struct>] to satisfy StructDiscriminatedUnionAnalyzer#4665

Merged
dbrattli merged 1 commit into
mainfrom
refactor/struct-discriminated-unions
Jun 16, 2026
Merged

refactor(all): mark enum-like DUs [<Struct>] to satisfy StructDiscriminatedUnionAnalyzer#4665
dbrattli merged 1 commit into
mainfrom
refactor/struct-discriminated-unions

Conversation

@dbrattli

Copy link
Copy Markdown
Collaborator

Summary

Resolves the editable IONIDE-012 (StructDiscriminatedUnionAnalyzer) code scanning alerts by marking the flagged discriminated unions [<Struct>] — the same pattern already used for FieldNamingKind, ClassStyle, and Atom.

62 alerts across 20 files are addressed:

  • The majority are enum-like / single-case / already-named-field DUs needing only the [<Struct>] attribute (bulk in Rust.AST.Types.fs ×26, Python.AST.fs ×6, Global/Babel.fs ×6, Dart/Dart.fs ×4, …).
  • 8 multicase DUs with unnamed fields also required unique field names to satisfy the struct-union rule (FS3585). Positional pattern matching is preserved, so call sites are unaffected:
    • Php.fs: PhpConst, PhpArrayIndex, Capture, PhpCase
    • Fable2Php.fs: ReturnStrategy
    • FSharp2Fable.Util.fs: CompiledValue
    • Globbing.fs (+ its .fsi signature): SearchOption
    • Util.fs: AttParam

Left untouched

The 8 IONIDE-012 alerts in src/Fable.AST/ (Common.fs, Fable.fs, Plugins.fs) are intentionally not changed. Adding [<Struct>] there would flip a public type from a reference type to a value type — a breaking change disallowed for that project.

Verification

  • Fable.Cli (→ Fable.Transforms + Fable.Compiler) and Fable.Standalone build clean.
  • No reference-identity / null / Unchecked.defaultof usages on the changed compiler-logic types (the only behavioral axis [<Struct>] affects).
  • JavaScript quicktest compiles and runs end-to-end with the freshly built compiler.

🤖 Generated with Claude Code

…inatedUnionAnalyzer

Resolve the editable IONIDE-012 (StructDiscriminatedUnionAnalyzer) code
scanning alerts by marking the flagged discriminated unions as structs.

Most are enum-like/single-case DUs needing only the [<Struct>] attribute.
A few multicase DUs with unnamed fields also required unique field names
to satisfy the struct-union rule (FS3585); positional pattern matching is
preserved so call sites are unaffected:

  - Php.fs: PhpConst, PhpArrayIndex, Capture, PhpCase
  - Fable2Php.fs: ReturnStrategy
  - FSharp2Fable.Util.fs: CompiledValue
  - Globbing.fs (+ .fsi): SearchOption
  - Util.fs: AttParam

Alerts in src/Fable.AST/ are intentionally left untouched: adding
[<Struct>] there would change a public type from reference to value type,
a breaking change disallowed for that project.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Python Type Checking Results (Pyright)

Metric Value
Total errors 34
Files with errors 4
Excluded files 4
New errors ✅ No
Excluded files with errors (4 files)

These files have known type errors and are excluded from CI. Remove from pyrightconfig.ci.json as errors are fixed.

File Errors Status
temp/tests/Python/test_hash_set.py 18 Excluded
temp/tests/Python/test_applicative.py 12 Excluded
temp/tests/Python/test_nested_and_recursive_pattern.py 2 Excluded
temp/tests/Python/fable_modules/thoth_json_python/encode.py 2 Excluded

@dbrattli dbrattli merged commit 3682b63 into main Jun 16, 2026
53 of 54 checks passed
@dbrattli dbrattli deleted the refactor/struct-discriminated-unions branch June 16, 2026 06:01
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