Skip to content

Commit 79e4b4e

Browse files
Fix #2342: DU tests must be recompiled
1 parent e85be78 commit 79e4b4e

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/Fable.Transforms/FSharp2Fable.Util.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,11 @@ module Helpers =
436436
let makeRangeFrom (fsExpr: FSharpExpr) =
437437
Some (makeRange fsExpr.Range)
438438

439-
let unionCaseTag (ent: FSharpEntity) (unionCase: FSharpUnionCase) =
439+
let unionCaseTag (com: IFableCompiler) (ent: FSharpEntity) (unionCase: FSharpUnionCase) =
440440
try
441+
// If the order of cases changes in the declaration, the tag has to change too.
442+
// Mark all files using the case tag as watch dependencies.
443+
com.AddWatchDependency(FsEnt.SourcePath ent)
441444
ent.UnionCases |> Seq.findIndex (fun uci -> unionCase.Name = uci.Name)
442445
with _ ->
443446
failwithf "Cannot find case %s in %s" unionCase.Name (FsEnt.FullName ent)

src/Fable.Transforms/FSharp2Fable.fs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,7 @@ let private transformNewUnion com ctx r fsType (unionCase: FSharpUnionCase) (arg
8484
Fable.NewList(headAndTail, typ) |> makeValue r
8585
| DiscriminatedUnion(tdef, genArgs) ->
8686
let genArgs = makeGenArgs ctx.GenericArgs genArgs
87-
let tag = unionCaseTag tdef unionCase
88-
// If the order of cases changes in the declaration, the tag has to change too
89-
// mark all files calling the union constructor as watch dependencies
90-
com.AddWatchDependency(FsEnt.SourcePath tdef)
87+
let tag = unionCaseTag com tdef unionCase
9188
Fable.NewUnion(argExprs, tag, FsEnt.Ref tdef, genArgs) |> makeValue r
9289

9390
let private transformTraitCall com (ctx: Context) r typ (sourceTypes: Fable.Type list) traitName (flags: MemberFlags) (argTypes: Fable.Type list) (argExprs: Fable.Expr list) =
@@ -263,7 +260,7 @@ let private transformUnionCaseTest (com: IFableCompiler) (ctx: Context) r
263260
| StringEnum(_, rule) ->
264261
return makeEqOp r unionExpr (transformStringEnum rule unionCase) BinaryEqualStrict
265262
| DiscriminatedUnion(tdef,_) ->
266-
let tag = unionCaseTag tdef unionCase
263+
let tag = unionCaseTag com tdef unionCase
267264
return Fable.Test(unionExpr, Fable.UnionCaseTest(tag), r)
268265
}
269266

@@ -730,7 +727,11 @@ let private transformExpr (com: IFableCompiler) (ctx: Context) fsExpr =
730727
let field = FsField field :> Fable.Field |> Fable.FieldKey |> Some
731728
return Fable.Set(callee, field, value, makeRangeFrom fsExpr)
732729

733-
| BasicPatterns.UnionCaseTag(unionExpr, _unionType) ->
730+
| BasicPatterns.UnionCaseTag(unionExpr, unionType) ->
731+
// TODO: This is an inconsistency. For new unions and union tests we calculate
732+
// the tag in this step but here we delay the calculation until Fable2Babel
733+
do tryDefinition unionType
734+
|> Option.iter (fun (tdef, _) -> com.AddWatchDependency(FsEnt.SourcePath tdef))
734735
let! unionExpr = transformExpr com ctx unionExpr
735736
return Fable.Get(unionExpr, Fable.UnionTag, Fable.Any, makeRangeFrom fsExpr)
736737

0 commit comments

Comments
 (0)