Skip to content

Commit c904844

Browse files
authored
Added null test for AddBoundValue. Making FsiTests single-threaded (#9184)
1 parent fe7c56a commit c904844

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/fsharp/fsi/fsi.fs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2922,15 +2922,19 @@ type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], i
29222922
member __.TryFindBoundValue(name: string) =
29232923
fsiDynamicCompiler.TryFindBoundValue(fsiInteractionProcessor.CurrentState, name)
29242924

2925-
member __.AddBoundValue(name: string, reflectionValue: obj) =
2925+
member __.AddBoundValue(name: string, value: obj) =
2926+
match value with
2927+
| null -> nullArg "value"
2928+
| _ -> ()
2929+
29262930
// Explanation: When the user of the FsiInteractiveSession object calls this method, the
29272931
// code is parsed, checked and evaluated on the calling thread. This means EvalExpression
29282932
// is not safe to call concurrently.
29292933
let ctok = AssumeCompilationThreadWithoutEvidence()
29302934

29312935
let errorOptions = TcConfig.Create(tcConfigB, validate = false).errorSeverityOptions
29322936
let errorLogger = CompilationErrorLogger("AddBoundValue", errorOptions)
2933-
fsiInteractionProcessor.AddBoundValue(ctok, errorLogger, name, reflectionValue)
2937+
fsiInteractionProcessor.AddBoundValue(ctok, errorLogger, name, value)
29342938
let errs = errorLogger.GetErrors()
29352939
ErrorHelpers.CreateErrorInfos (errorOptions, true, "input.fsx", errs, true)
29362940

src/fsharp/fsi/fsi.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ type FsiEvaluationSession =
269269
/// Creates a root-level value with the given name and .NET object.
270270
/// If the .NET object contains types from assemblies that are not referenced in the interactive session, it will try to implicitly resolve them by default configuration.
271271
/// Name must be a valid identifier.
272-
member AddBoundValue : name: string * reflectionValue: obj -> FSharpErrorInfo[]
272+
member AddBoundValue : name: string * value: obj -> FSharpErrorInfo[]
273273

274274
/// Load the dummy interaction, load the initial files, and,
275275
/// if interacting, start the background thread to read the standard input.

tests/FSharp.Compiler.UnitTests/FsiTests.fs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
module FSharp.Compiler.UnitTests.FsiTests
1+
[<NUnit.Framework.SingleThreaded>]
2+
module FSharp.Compiler.UnitTests.FsiTests
23

4+
open System
35
open System.IO
46
open FSharp.Compiler.Interactive.Shell
57
open NUnit.Framework
@@ -404,6 +406,12 @@ let ``Creation of a bound value fails if the name contains dots`` () =
404406
Assert.AreEqual(FSharpErrorSeverity.Error, error.Severity)
405407
Assert.AreEqual("Identifier expected", error.Message)
406408

409+
[<Test>]
410+
let ``Creation of a bound value throws if the value passed is null`` () =
411+
use fsiSession = createFsiSession ()
412+
413+
Assert.Throws<ArgumentNullException>(fun () -> fsiSession.AddBoundValue("x", null) |> ignore) |> ignore
414+
407415
[<Test>]
408416
let ``Creation of a bound value succeeds if the value contains types from assemblies that are not referenced in the session, due to implicit resolution`` () =
409417
use fsiSession = createFsiSession ()

0 commit comments

Comments
 (0)