@@ -3520,34 +3520,40 @@ module internal ProjectForWitnessConditionalComparison =
35203520 /// This triggers the bug because it forces conversion of auto-generated comparison code
35213521 let walkAllExpressions (source : string) =
35223522 let fileName1 = System.IO.Path.ChangeExtension(getTemporaryFileName (), ".fs")
3523- FileSystem.OpenFileForWriteShim(fileName1).Write(source)
3524- let options = createProjectOptions [source] []
3525- let exprChecker = FSharpChecker.Create(keepAssemblyContents=true, useTransparentCompiler=CompilerAssertHelpers.UseTransparentCompiler)
3526- let wholeProjectResults = exprChecker.ParseAndCheckProject(options) |> Async.RunImmediate
3527-
3528- if wholeProjectResults.Diagnostics.Length > 0 then
3529- for diag in wholeProjectResults.Diagnostics do
3530- printfn "Diagnostic: %s" diag.Message
3531-
3532- for implFile in wholeProjectResults.AssemblyContents.ImplementationFiles do
3533- // Walk all declarations and their expressions, including ImmediateSubExpressions
3534- let rec walkExpr (e: FSharpExpr) =
3535- // Access ImmediateSubExpressions - this is what triggers the bug
3536- for subExpr in e.ImmediateSubExpressions do
3537- walkExpr subExpr
3538-
3539- let rec walkDecl d =
3540- match d with
3541- | FSharpImplementationFileDeclaration.Entity (_, subDecls) ->
3542- for subDecl in subDecls do
3543- walkDecl subDecl
3544- | FSharpImplementationFileDeclaration.MemberOrFunctionOrValue (_, _, e) ->
3545- walkExpr e
3546- | FSharpImplementationFileDeclaration.InitAction e ->
3547- walkExpr e
3548-
3549- for decl in implFile.Declarations do
3550- walkDecl decl
3523+ try
3524+ FileSystem.OpenFileForWriteShim(fileName1).Write(source)
3525+ let options = createProjectOptions [source] []
3526+ let exprChecker = FSharpChecker.Create(keepAssemblyContents=true, useTransparentCompiler=CompilerAssertHelpers.UseTransparentCompiler)
3527+ let wholeProjectResults = exprChecker.ParseAndCheckProject(options) |> Async.RunImmediate
3528+
3529+ if wholeProjectResults.Diagnostics.Length > 0 then
3530+ for diag in wholeProjectResults.Diagnostics do
3531+ printfn "Diagnostic: %s" diag.Message
3532+
3533+ for implFile in wholeProjectResults.AssemblyContents.ImplementationFiles do
3534+ // Walk all declarations and their expressions, including ImmediateSubExpressions
3535+ let rec walkExpr (e: FSharpExpr) =
3536+ // Access ImmediateSubExpressions - this is what triggered #19118
3537+ for subExpr in e.ImmediateSubExpressions do
3538+ walkExpr subExpr
3539+
3540+ let rec walkDecl d =
3541+ match d with
3542+ | FSharpImplementationFileDeclaration.Entity (_, subDecls) ->
3543+ for subDecl in subDecls do
3544+ walkDecl subDecl
3545+ | FSharpImplementationFileDeclaration.MemberOrFunctionOrValue (_, _, e) ->
3546+ walkExpr e
3547+ | FSharpImplementationFileDeclaration.InitAction e ->
3548+ walkExpr e
3549+
3550+ for decl in implFile.Declarations do
3551+ walkDecl decl
3552+ finally
3553+ try
3554+ FileSystem.FileDeleteShim fileName1
3555+ with
3556+ | _ -> ()
35513557
35523558[<Fact>]
35533559let ``ImmediateSubExpressions - generic DU with no constraints should not crash`` () =
@@ -3559,7 +3565,7 @@ module M
35593565type Bar<'appEvent> =
35603566 | Wibble of 'appEvent
35613567"""
3562- // This should not throw - before the fix it crashes with ConstraintSolverMissingConstraint
3568+ // This should not throw. Before the fix, it crashed with ConstraintSolverMissingConstraint.
35633569 ProjectForWitnessConditionalComparison.walkAllExpressions source
35643570
35653571[<Fact>]
@@ -3609,7 +3615,8 @@ and Inner<'b> =
36093615
36103616[<Fact>]
36113617let ``ImmediateSubExpressions - generic DU with explicit comparison constraint works`` () =
3612- // When the type parameter HAS the comparison constraint, witness generation should work
3618+ // When the type parameter has the comparison constraint, witness generation should work;
3619+ // no crash occurred even before the bug was fixed. This test is here for completeness.
36133620 let source = """
36143621module M
36153622
@@ -3620,7 +3627,7 @@ type WithConstraint<'a when 'a : comparison> =
36203627
36213628[<Fact>]
36223629let ``ImmediateSubExpressions - non-generic DU works`` () =
3623- // Non-generic types should work fine (no generics = no witness issues)
3630+ // Non-generic types always worked fine (no generics = no witness issues). This test is here for completeness.
36243631 let source = """
36253632module M
36263633
@@ -3632,7 +3639,8 @@ type SimpleUnion =
36323639
36333640[<Fact>]
36343641let ``ImmediateSubExpressions - generic DU with NoComparison attribute should not crash`` () =
3635- // With NoComparison, no comparison code is generated, so no crash should occur
3642+ // With NoComparison, no comparison code is generated, so no crash ever occurred even before the bug was fixed.
3643+ // This test is here for completeness.
36363644 let source = """
36373645module M
36383646
0 commit comments