Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statics in class outlive the instances #866

Closed
bclothier opened this issue May 23, 2022 · 1 comment
Closed

Statics in class outlive the instances #866

bclothier opened this issue May 23, 2022 · 1 comment
Labels
bug Something isn't working confirmed the issue has been verified

Comments

@bclothier
Copy link
Collaborator

Describe the bug
If there is a static variable within a class, it ends up outliving the instance, which may then lead to crashes in IDE and strange behaviors in VBx.

To Reproduce

  1. Create a project and add the following code:
Private Class WhatIs
    Public Function IsTheNumber() As Long
        Static i As Long
        i += 1
        Return i
    End Function
End Class
Private Module Who
	Public Sub Colombo()
    	With New WhatIs
        	Debug.Print .IsTheNumber
    	End With
	End Sub
    Public Sub Holmes()
    	With New WhatIs
        	Debug.Print .IsTheNumber
    	End With
    End Sub
    Public Sub Dunnit()
        Colombo
        Holmes
    End Sub
End Module
  1. Run the Who.Dunnit
  2. Observe the debug console output. Repeat few times and you will see it continue to increase when it should have had reset.

Expected behavior
The static variable should be reset and be independent between instances.

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows 10
  • twinBASIC IDE Beta 46
@WaynePhillipsEA WaynePhillipsEA added bug Something isn't working confirmed the issue has been verified labels May 23, 2022
@WaynePhillipsEA
Copy link
Collaborator

Fixed in BETA 47, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working confirmed the issue has been verified
Projects
None yet
Development

No branches or pull requests

2 participants