diff --git a/IDE/Tests/Test1/scripts/HotSwap_StringLiterals.txt b/IDE/Tests/Test1/scripts/HotSwap_StringLiterals.txt new file mode 100644 index 000000000..3f6dec57d --- /dev/null +++ b/IDE/Tests/Test1/scripts/HotSwap_StringLiterals.txt @@ -0,0 +1,20 @@ +ShowFile("src/HotSwap_StringLiterals.bf") + +# Build with the literal, then remove its usage and rebuild without cleaning. +ToggleCommentAt("UseString") +Compile() +AssertCompileSucceeded() +ToggleCommentAt("UseString") +Compile() +AssertCompileSucceeded() + +GotoText("//StringPool_Start") +ToggleBreakpoint() +RunWithCompiling() +AssertEvalEquals("GetLength()", "0") + +# The hot update must emit the literal omitted from the executable being debugged. +ToggleCommentAt("UseString") +Compile() +AssertCompileSucceeded() +AssertEvalEquals("GetLength()", "15") diff --git a/IDE/Tests/Test1/src/HotSwap_StringLiterals.bf b/IDE/Tests/Test1/src/HotSwap_StringLiterals.bf new file mode 100644 index 000000000..64d65fc85 --- /dev/null +++ b/IDE/Tests/Test1/src/HotSwap_StringLiterals.bf @@ -0,0 +1,30 @@ +using System; + +#pragma warning disable 168 + +namespace IDETest +{ + class HotSwap_StringLiterals + { + // A separate module lets the literal become unused when its call is removed. + class StringSource + { + public static String GetValue() => "hot-swap string"; + } + + static int GetLength() + { + int length = 0; + /*UseString + length = StringSource.GetValue().Length; + */ + return length; + } + + public static void Test() + { + //StringPool_Start + int length = GetLength(); + } + } +} diff --git a/IDE/Tests/Test1/src/Program.bf b/IDE/Tests/Test1/src/Program.bf index 43cce05d0..058bfefe0 100644 --- a/IDE/Tests/Test1/src/Program.bf +++ b/IDE/Tests/Test1/src/Program.bf @@ -21,6 +21,7 @@ namespace IDETest HotSwap_LiveTypes.Test(); HotSwap_LocateSym01.Test(); HotSwap_Reflection.Test(); + HotSwap_StringLiterals.Test(); HotSwap_TLS.Test(); InlineTester.Test(); LambdaTester.Test(); diff --git a/IDEHelper/Compiler/BfCompiler.cpp b/IDEHelper/Compiler/BfCompiler.cpp index bfd6227d8..eda915f92 100644 --- a/IDEHelper/Compiler/BfCompiler.cpp +++ b/IDEHelper/Compiler/BfCompiler.cpp @@ -1453,6 +1453,8 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) CompileLog("VData unchanged, skipping\n"); return; } + if (!isHotCompile) + bfModule->mDefinedStrings.Clear(); auto typeResolveModule = mContext->mUnreifiedModule; BfTypeInstance* stringType = typeResolveModule->ResolveTypeDef(mStringTypeDef, BfPopulateType_Data)->ToTypeInstance();