From dc32318cecfbb2396c68085724ec4c83438ec3ea Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 12 Mar 2023 18:16:48 +0100 Subject: [PATCH] fix possible string error on inlined subroutines --- .../src/prog8/optimizer/UnusedCodeRemover.kt | 4 +++- compiler/test/TestOptimization.kt | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/codeOptimizers/src/prog8/optimizer/UnusedCodeRemover.kt b/codeOptimizers/src/prog8/optimizer/UnusedCodeRemover.kt index cf546afdd..3bb14cee4 100644 --- a/codeOptimizers/src/prog8/optimizer/UnusedCodeRemover.kt +++ b/codeOptimizers/src/prog8/optimizer/UnusedCodeRemover.kt @@ -100,7 +100,9 @@ class UnusedCodeRemover(private val program: Program, if(!subroutine.definingModule.isLibrary && !subroutine.hasBeenInlined) { errors.warn("unused subroutine '${subroutine.name}'", subroutine.position) } - program.removeInternedStringsFromRemovedSubroutine(subroutine) + if(!subroutine.inline) { + program.removeInternedStringsFromRemovedSubroutine(subroutine) + } return listOf(IAstModification.Remove(subroutine, parent as IStatementContainer)) } } diff --git a/compiler/test/TestOptimization.kt b/compiler/test/TestOptimization.kt index 771e63284..6df9b8ee7 100644 --- a/compiler/test/TestOptimization.kt +++ b/compiler/test/TestOptimization.kt @@ -764,6 +764,20 @@ main { sub start() { sort(cards) } +}""" + compileText(C64Target(), true, text, writeAssembly = false) shouldNotBe null + } + + test("no string error when inlining") { + val text=""" +main { + sub start() { + test() + } + + sub test() { + cx16.r0 = "abc" + } }""" compileText(C64Target(), true, text, writeAssembly = false) shouldNotBe null }