Bug 160321

Summary: On GoSub statement does not work properly
Product: LibreOffice Reporter: Jean-Pierre Sanchez <jeanpierresanchez0000>
Component: BASICAssignee: Andreas Heinisch <andreas.heinisch>
Status: ASSIGNED ---    
Severity: normal CC: andreas.heinisch, jeanpierresanchez0000, raal, rafael.palma.lima
Priority: medium    
Version: 4.1.0.4 release   
Hardware: All   
OS: All   
Whiteboard:
Crash report or crash signature: Regression By:
Bug Depends on:    
Bug Blocks: 107659    
Attachments: Result from the macro

Description Jean-Pierre Sanchez 2024-03-22 20:45:11 UTC
Description:
The statement 'On expression GoSub' does not work properly. When expression is 0, the statement GoSub should not be executed. Actually it is executed on the following line.
When statements GoSub are imbricated the next Return statement does not jump to the proper line.

Steps to Reproduce:
Sub Main
Dim i As Integer
	GoSub Sub1
	Print i
Exit Sub
Sub1: 
	On 1 GoSub SubA, SubB
	i=i+1
	Return
SubA: Return
SubB: Return
End Sub

Actual Results:
2
Because the line i=i+1 is executed twice!

Expected Results:
1


Reproducible: Always


User Profile Reset: No

Additional Info:
[Information automatically included from LibreOffice]
Locale: en-US
Module: BasicIDE
[Information guessed from browser]
OS: Mac OS X (All)
OS is 64bit: no
Comment 1 Rafael Lima 2024-03-22 23:56:48 UTC
I copied the code, pasted it on the Basic IDE and ran it... I got 1 as result.

Can you test this again?

System info

Version: 24.2.1.2 (X86_64) / LibreOffice Community
Build ID: 420(Build:2)
CPU threads: 12; OS: Linux 6.5; UI render: default; VCL: kf5 (cairo+wayland)
Locale: pt-BR (pt_BR.UTF-8); UI: en-US
Ubuntu package version: 4:24.2.1~rc2-0ubuntu0.23.10.1~lo1
Calc: threaded
Comment 2 Rafael Lima 2024-03-22 23:58:49 UTC
Created attachment 193251 [details]
Result from the macro
Comment 3 Jean-Pierre Sanchez 2024-03-23 07:54:22 UTC
Thanks Rafael for your quick response.

I made a mistake when I copied the code.
Change 'On 1 GoSub SubA, SubB' By 'On 0 GoSub SubA, SubB'
You'll get 2 as result
Cheers
Comment 4 Jean-Pierre Sanchez 2024-03-26 12:23:32 UTC
Hello

Could you tell me if you get the same result when you run the following code?
Cheers

Sub Main
Dim i As Integer
	GoSub Sub1
	Print i
Exit Sub
Sub1: 
	On 0 GoSub SubA, SubB
	i=i+1
	Return
SubA: Return
SubB: Return
End Sub
Comment 5 raal 2024-03-26 12:40:18 UTC
I can confirm with Version 4.1.0.0.alpha0+ (Build ID: efca6f15609322f62a35619619a6d5fe5c9bd5a)
and
Version: 24.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 2887ffbf240aa70330cb50bf810170cf9c896405
CPU threads: 4; OS: Linux 6.5; UI render: default; VCL: gtk3
Locale: cs-CZ (cs_CZ.UTF-8); UI: en-US
Calc: threaded Jumbo

Help: https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03090303.html?DbPAR=BASIC#bm_id3153897
"If expression is 0, the statement is not executed."
Comment 6 Rafael Lima 2024-03-28 12:45:00 UTC
@Andreas, this one might interest you.
Comment 7 Andreas Heinisch 2024-03-28 14:24:35 UTC
Thank you Rafael for the ping. It is on my list. Lot of work currently so less libreoffice  :(