From 925770dddbebac93f48ba4a941930a584ff3be52 Mon Sep 17 00:00:00 2001 From: Kevin Ransom Date: Wed, 18 Oct 2023 16:57:48 -0700 Subject: [PATCH] Fix - 16118 : Regression: Cannot use two or more open sessions in FCS 43.7.200+ --- src/Compiler/Checking/CheckDeclarations.fs | 2 +- src/Compiler/Interactive/fsi.fs | 6 ++-- .../Scripting/Interactive.fs | 32 +++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 1c0997851e4..7cbc0358a29 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -259,7 +259,7 @@ let BuildRootModuleContents (isModule: bool) enclosingNamespacePath (cpath: Comp ||> List.foldBack (fun id (cpath, moduleContents) -> (cpath.ParentCompPath, wrapModuleOrNamespaceContentsInNamespace isModule id cpath.ParentCompPath moduleContents)) |> snd -/// Try to take the "FSINNN" prefix off a namespace path +/// Try to take the "FSI_NNN" prefix off a namespace path let TryStripPrefixPath (g: TcGlobals) (enclosingNamespacePath: Ident list) = match enclosingNamespacePath with | p :: rest when diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index 6eaa8a713e5..671e0a15f5c 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -1837,7 +1837,7 @@ type internal FsiDynamicCompiler let opts = { ilg = tcGlobals.ilg - outfile = multiAssemblyName + ".dll" + outfile = $"{multiAssemblyName}-{dynamicAssemblyId}.dll" pdbfile = Some(Path.Combine(scriptingSymbolsPath.Value, $"{multiAssemblyName}-{dynamicAssemblyId}.pdb")) emitTailcalls = tcConfig.emitTailcalls deterministic = tcConfig.deterministic @@ -3306,8 +3306,8 @@ type internal MagicAssemblyResolution() = | None -> // Check dynamic assemblies by simple name match fsiDynamicCompiler.FindDynamicAssembly(simpleAssemName, false) with - | Some asm -> asm - | None -> + | Some asm when not (tcConfigB.fsiMultiAssemblyEmit) -> asm + | _ -> // Otherwise continue let assemblyReferenceTextDll = (simpleAssemName + ".dll") diff --git a/tests/FSharp.Compiler.ComponentTests/Scripting/Interactive.fs b/tests/FSharp.Compiler.ComponentTests/Scripting/Interactive.fs index 06eecf708ac..58f90304853 100644 --- a/tests/FSharp.Compiler.ComponentTests/Scripting/Interactive.fs +++ b/tests/FSharp.Compiler.ComponentTests/Scripting/Interactive.fs @@ -5,8 +5,11 @@ namespace Scripting open Xunit open System open FSharp.Test.Compiler +open FSharp.Compiler.Interactive.Shell +open FSharp.Test.ScriptHelpers module ``Interactive tests`` = + [] let ``Eval object value``() = Fsx "1+1" @@ -31,6 +34,35 @@ module ``Interactive tests`` = (Warning 2304, Line 1, Col 3, Line 1, Col 13, "Functions with [] are not invoked in FSI. 'myFunc' was not invoked. Execute 'myFunc ' in order to invoke 'myFunc' with the appropriate string array of command line arguments.") ] + [] + [] + [] + let ``Evaluation of multiple sessions should succeed`` (useMultiEmit) = + + let args : string array = [| if useMultiEmit then "--multiemit+" else "--multiemit-"|] + use sessionOne = new FSharpScript(additionalArgs=args) + use sessionTwo = new FSharpScript(additionalArgs=args) + + sessionOne.Eval(""" +module Test1 = + + let test1 obj = sprintf "Execute - Test1.test1 - %A" obj""") |> ignore + + let result1 = sessionOne.Eval("""Test1.test1 18""") |> getValue + let value1 = result1.Value + Assert.Equal(typeof, value1.ReflectionType) + Assert.Equal("Execute - Test1.test1 - 18", value1.ReflectionValue :?> string) + + sessionTwo.Eval(""" +module Test2 = + + let test2 obj = sprintf "Execute - Test2.test2 - %A" obj""") |> ignore + + let result2 = sessionTwo.Eval("""Test2.test2 27""") |> getValue + let value2 = result2.Value + Assert.Equal(typeof, value2.ReflectionType) + Assert.Equal("Execute - Test2.test2 - 27", value2.ReflectionValue :?> string) + module ``External FSI tests`` = [] let ``Eval object value``() =