basic/qa/basic_coverage/test_With.bas | 9 +++++++++ basic/source/comp/loops.cxx | 15 +++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-)
New commits: commit fa8a0f514a4c722974410e4cbfa8ea12f3304003 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sun Aug 18 12:09:27 2024 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sun Aug 18 10:26:26 2024 +0200 Related: tdf#132064 Use set to clear the With internal variable In commit f3f46b5fe729876d128f63f7ab158954ab6657d7 (tdf#132064: make With statement only evaluate its argument once, 2024-08-17), I made a mistake, clearing the internal variable in the end of SbiParser::With using an Erase call, which does not just clears the variable itself, but destroys the underlying object, which is not what we need. I don't know how to refer to a global Nothing object to assign to the variable; so just create an own internal Nothing, and use it in the assignment. Change-Id: Ic8ce52e0402d8461a9b9e4ee07614c4f0a46a95e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172006 Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Tested-by: Jenkins diff --git a/basic/qa/basic_coverage/test_With.bas b/basic/qa/basic_coverage/test_With.bas index 389b89090d9b..b7bf439a01a4 100644 --- a/basic/qa/basic_coverage/test_With.bas +++ b/basic/qa/basic_coverage/test_With.bas @@ -45,6 +45,15 @@ Sub test_with ' Field values returned n = 0 s = , expected n = 5 s = bar TestUtil.AssertEqual(fields, "n = 5 s = bar", "Field values") + ' Make sure that With works with the original object, modifies it, and does not destroy + Dim foo_var As New foo + With foo_var + .n = 6 + .s = "baz" + End With + fields = "n = " & foo_var.n & " s = " & foo_var.s + TestUtil.AssertEqual(fields, "n = 6 s = baz", "Field values of foo_var") + Exit Sub errorHandler: TestUtil.ReportErrorHandler("test_with", Err, Error$, Erl) diff --git a/basic/source/comp/loops.cxx b/basic/source/comp/loops.cxx index 0b15c55f3c33..bab033c49608 100644 --- a/basic/source/comp/loops.cxx +++ b/basic/source/comp/loops.cxx @@ -327,9 +327,20 @@ void SbiParser::With() StmntBlock( ENDWITH ); CloseBlock(); - // Erase {_with_library.module_offset} + // {_with_library.module_offset} = Nothing + // I don't know how to refer to the global Nothing constant here; just create an own + constexpr OUString aNothingName = u"{_with_Nothing}"_ustr; + SbiSymDef* pNothingDef = pPool->Find(aNothingName); + if (!pNothingDef) + { + pNothingDef = new SbiSymDef(aNothingName); + pNothingDef->SetType(SbxOBJECT); + pPool->Add(pNothingDef); + aGen.Gen(SbiOpcode::LOCAL_, pNothingDef->GetId(), pNothingDef->GetType()); + } aWithParent.Gen(); - aGen.Gen(SbiOpcode::ERASE_); + SbiExpression(this, *pNothingDef).Gen(); + aGen.Gen(SbiOpcode::SET_); } // LOOP/NEXT/WEND without construct