Skip to content

Commit 3682b63

Browse files
dbrattliclaude
andauthored
refactor(all): mark enum-like DUs [<Struct>] to satisfy StructDiscriminatedUnionAnalyzer (#4665)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 883b16d commit 3682b63

19 files changed

Lines changed: 87 additions & 25 deletions

src/Fable.Compiler/Globbing.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ module Glob =
1818
let inline normalizePath (path: string) =
1919
path.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar)
2020

21+
[<Struct>]
2122
type private SearchOption =
22-
| Directory of string
23-
| Drive of string
23+
| Directory of dir: string
24+
| Drive of drive: string
2425
| Recursive
25-
| FilePattern of string
26+
| FilePattern of pattern: string
2627

2728
let private checkSubDirs absolute (dir: string) root =
2829
if dir.Contains "*" then

src/Fable.Compiler/Globbing.fsi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ module Glob =
1515

1616
val inline normalizePath: path: string -> string
1717

18+
[<Struct>]
1819
type private SearchOption =
19-
| Directory of string
20-
| Drive of string
20+
| Directory of dir: string
21+
| Drive of drive: string
2122
| Recursive
22-
| FilePattern of string
23+
| FilePattern of pattern: string
2324

2425
val internal getRoot: baseDirectory: string -> pattern: string -> string
2526
val internal search: baseDir: string -> originalInput: string -> string list

src/Fable.Compiler/Util.fs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,11 +705,12 @@ module Json =
705705
open Fable.AST
706706

707707
// TODO: Check which other parameters are accepted by attributes (arrays?)
708+
[<Struct>]
708709
type AttParam =
709-
| Int of int
710-
| Float of float
711-
| Bool of bool
712-
| String of string
710+
| Int of intValue: int
711+
| Float of floatValue: float
712+
| Bool of boolValue: bool
713+
| String of stringValue: string
713714

714715
static member From(values: obj list) =
715716
(Ok [], values)

src/Fable.Transforms/Dart/Dart.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// Loosely based on https://pub.dev/documentation/analyzer/latest/dart_ast_ast/dart_ast_ast-library.html
22
module rec Fable.AST.Dart
33

4+
[<Struct>]
45
type UpdateOperator =
56
| UpdateMinus
67
| UpdatePlus
78

9+
[<Struct>]
810
type AssignmentOperator =
911
| AssignEqual
1012
| AssignMinus
@@ -259,6 +261,7 @@ type Expression =
259261
static member throwExpression(value, typ) = ThrowExpression(value, typ)
260262
static member rethrowExpression(typ) = RethrowExpression typ
261263

264+
[<Struct>]
262265
type VariableDeclarationKind =
263266
| Final
264267
| Const
@@ -378,6 +381,7 @@ type InstanceVariable(ident, ?value, ?kind, ?isOverride, ?isLate) =
378381
member _.IsOverride = defaultArg isOverride false
379382
member _.IsLate = defaultArg isLate false
380383

384+
[<Struct>]
381385
type MethodKind =
382386
| IsMethod
383387
| IsGetter

src/Fable.Transforms/Dart/DartPrinter.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ open Fable.AST
66
open Fable.AST.Dart
77
open Fable.Transforms.Printer
88

9+
[<Struct>]
910
type ListPos =
1011
| IsFirst
1112
| IsMiddle

src/Fable.Transforms/Dart/Fable2Dart.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type Context =
6262

6363
{ this with EntityAndMemberGenericParams = this.EntityAndMemberGenericParams @ genParams }
6464

65+
[<Struct>]
6566
type MemberKind =
6667
| ClassConstructor
6768
| NonAttached of funcName: string

src/Fable.Transforms/FSharp2Fable.Util.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ type FsField(fi: FSharpField) =
105105
| n -> name + "_" + (string<int> n)
106106

107107
[<RequireQualifiedAccess>]
108+
[<Struct>]
108109
type CompiledValue =
109-
| Integer of int
110-
| Float of float
111-
| Boolean of bool
110+
| Integer of intValue: int
111+
| Float of floatValue: float
112+
| Boolean of boolValue: bool
112113

113114
type FsUnionCase(uci: FSharpUnionCase) =
114115
/// FSharpUnionCase.CompiledName doesn't give the value of CompiledNameAttribute

src/Fable.Transforms/Fable2Babel.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type ReturnStrategy =
1313
| Assign of Expression
1414
| Target of Identifier
1515

16+
[<Struct>]
1617
type ConstructorRef =
1718
| Annotation
1819
| ActualConsRef
@@ -1329,6 +1330,7 @@ module Util =
13291330

13301331
scopedTypeParams, typeParams
13311332

1333+
[<Struct>]
13321334
type MemberKind =
13331335
| ClassConstructor
13341336
| NonAttached of funcName: string

src/Fable.Transforms/Global/Babel.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ namespace rec Fable.AST.Babel
33

44
open Fable.AST
55

6+
[<Struct>]
67
type UpdateOperator =
78
| UpdateMinus
89
| UpdatePlus
910

11+
[<Struct>]
1012
type AssignmentOperator =
1113
| AssignEqual
1214
| AssignMinus
@@ -204,6 +206,7 @@ type Declaration =
204206

205207
/// A directive prologue as defined in ECMA specification
206208
/// https://tc39.es/ecma262/#sec-directive-prologues-and-the-use-strict-directive
209+
[<Struct>]
207210
type DirectivePrologue = | DirectivePrologue of text: string
208211

209212
/// A module import or export declaration.
@@ -300,6 +303,7 @@ type VariableDeclarator =
300303
init: Expression option *
301304
loc: SourceLocation option
302305

306+
[<Struct>]
303307
type VariableDeclarationKind =
304308
| Var
305309
| Let
@@ -412,6 +416,7 @@ type ObjectMember =
412416
// let shorthand = defaultArg shorthand_ false
413417
// member _.Shorthand: bool = shorthand
414418

419+
[<Struct>]
415420
type ObjectMethodKind =
416421
| ObjectGetter
417422
| ObjectSetter
@@ -440,6 +445,7 @@ type ObjectMethodKind =
440445

441446

442447
// Classes
448+
[<Struct>]
443449
type AccessModifier =
444450
| Public
445451
| Private

src/Fable.Transforms/Global/Compiler.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ type CompilerOptionsHelper =
3535
}
3636

3737
[<RequireQualifiedAccess>]
38+
[<Struct>]
3839
type Severity =
3940
| Warning
4041
| Error
4142
| Info
4243

4344
[<RequireQualifiedAccess>]
45+
[<Struct>]
4446
type OutputType =
4547
| Library
4648
| Exe

0 commit comments

Comments
 (0)