Option Explicit
Private mValue As Boolean
'Doesn't matter if this is commented out or not:
'
'Private Sub Class_Initialize()
'
'End Sub
Private Sub Class_Terminate()
'
End Sub
Public Property Get TheValue() As Boolean
TheValue = mValue
End Property
Public Property Let TheValue(ByVal value As Boolean)
mValue = value
End Property
then a stdmodule:
Option Explicit
Public Function CreateStoringClass(ByVal value As Boolean) As StoringClass
Dim result As StoringClass
Set result = New StoringClass
result.TheValue = value
Set CreateStoringClass = result
End Function
' Problem with Office 2013 64-Bit (incl. 2018-09, 15.0.5045.1000):
' This line of code works wrong:
' If Not Factory.CreateStoringClass(VALUE_TO_TEST).TheValue) Then
' Remark:
' The terminator in "StoringClass" causes this behaviour (even if it is empty).
' When it will be removed or commented out, it runs well!
there's a lot more junk and I've tweaked it a bit, but it does demonstrate the weirdness
output on 64-bit Excel is "This is wrong"
if I extract a local variable for the Create result, I get "This is correct"
Sub ShortTest()
Const VALUE_TO_TEST As Boolean = True
Debug.Print "Value to check: " & VALUE_TO_TEST
Dim result As StoringClass
Set result = CreateStoringClass(VALUE_TO_TEST)
If result.TheValue <> VALUE_TO_TEST Then
Debug.Print "This is wrong"
Else
Debug.Print "This is correct"
End If
End Sub
^ works as expected
Sub ShortTest()
Const VALUE_TO_TEST As Boolean = True
Debug.Print "Value to check: " & VALUE_TO_TEST
'Dim result As StoringClass
'Set result = CreateStoringClass(VALUE_TO_TEST)
If CreateStoringClass(VALUE_TO_TEST).TheValue <> VALUE_TO_TEST Then
Debug.Print "This is wrong"
Else
Debug.Print "This is correct"
End If
End Sub
No Class_Terminate handler, no local variable: OK
With Class_Terminate handler, no local variable: terminatingSurprise!
No Class_Terminate handler, with local variable: OK
With Class_Terminate handler, with local variable: OK
terminating
@Comintern so RD needs an inspection for inlined member calls, on user objects (?), I guess. "Object may get terminated before the member call is executed, on 64-bit hosts"
What I want to know is if it's creating the default instance to call the Property Get.
OK, what sort of WTFery is this?
Option Explicit
Private mValue As Boolean
Private Sub Class_Initialize()
Debug.Print "Initializing"
End Sub
Private Sub Class_Terminate()
Debug.Print "Terminating"
End Sub
Public Property Get TheValue() As Boolean
Debug.Print "Accessing TheValue"
TheValue = mValue
End Property
Public Property Let TheValue(ByVal value As Boolean)
Debug.Print "Setting TheValue"
mValue = value
End Property
Output:
Value to check: True
Initializing
Setting TheValue
Accessing TheValue
Terminating
This is wrong
Option Explicit
Private mValue As Boolean
Private instance As Integer
Private Sub Class_Initialize()
Static ctor As Integer
ctor = ctor + 1
instance = ctor
Debug.Print "Initializing " & instance
End Sub
Private Sub Class_Terminate()
Debug.Print "Terminating " & instance
End Sub
Public Property Get TheValue() As Boolean
Debug.Print "Accessing TheValue " & instance
TheValue = mValue
End Property
Public Property Let TheValue(ByVal value As Boolean)
Debug.Print "Setting TheValue " & instance
Only 1 is created.
Value to check: True
Initializing 1
Setting TheValue 1
Accessing TheValue 1
Terminating 1
This is wrong
Value to check: True
Initialized
Setting the value
Getting the value
Getting the result
Terminated
This is correct
(this is on 32-bit host, though)
using this version of test:
Function ShortResult() As Boolean
Debug.Print "Getting the result"
ShortResult = True
End Function
Sub ShortTest1()
Const VALUE_TO_TEST As Boolean = True
Debug.Print "Value to check: " & VALUE_TO_TEST
If CreateStoringClass(VALUE_TO_TEST).TheValue <> ShortResult Then
Debug.Print "This is wrong"
Else
Debug.Print "This is correct"
End If
End Sub
Is there a way in VS I can check to see if my version of RD is correct? I just want to quadruple check that I did this correctly before I start looking for something to work on
And the thing is, no matter how fast I try to close it before it barfs, it's never fast enough. It's like it waits for the IO to complete, but then doesn't care.
@Comintern ok I get the local variable thing. the part that eludes me is the different behavior when there is vs when there isn't a Terminate handler (be it empty or not)
Undefined compile-time behavior as opposed to run-time behavior?
For example, overflow behavior in C is undefined, but that means that any implementation of a C compiler can do whatever it wants when it encounters it.
For the tuple that returns from VBACodeString.Parser.Parse should I be looking at the parseTree to figure out how to navigate it for module declarations?
Implements IBar
Public Property Get Bar() As Long
End Property
Public Property Let Bar(ByRef rhs As Long)
End Property
Private Property Get IBar_Bar() As Long
End Property
Private Property Let IBar_Bar(ByRef rhs As Long)
End Property
hmm, actually my typical interface-implementing class would have the interface members, and then some - e.g. interface has Property Get, coclass has Property Let as well
> I don't believe these are creating references at all. I just discovered while hacking on #4299 that the following code doesn't generate an identifier reference for the `Property Get` on the `Debug.Print underTest.Bar` line of the code below:
``` Sub Testing() Dim underTest As Foo Set underTest = New Foo underTest.Bar = 42 Debug.Print underTest.Bar End Sub ```
[Test]
[Category("Inspections")]
public void ReferenceCountIsLegit()
{
const string inputCode =
@"Sub Testing()
Dim underTest As Foo
Set underTest = New Foo
underTest.Bar = 42
Debug.Print underTest.Bar
End Sub
";
using (var state = ArrangeParserAndParse(inputCode))
{
var declaration = state.AllUserDeclarations.FirstOrDefault(x => x.IdentifierName.Equals("underTest"));
Assert.AreEqual(4, declaration.References.Count());
An exception of type 'NUnit.Framework.AssertionException' occurred in nunit.framework.dll but was not handled in user code
Expected: 4
But was: 2
> # [Codecov](https://codecov.io/gh/rubberduck-vba/Rubberduck/pull/4418?src=pr&el=h1) Report > Merging [#4418](https://codecov.io/gh/rubberduck-vba/Rubberduck/pull/4418?src=pr&el=desc) into [next](https://codecov.io/gh/rubberduck-vba/Rubberduck/commit/f38ebf776c9de99883f2e3aca5e2291f0569bded?src=pr&el=desc) will **increase** coverage by `0.15%`. > The diff coverage is `56.03%`.
> # [Codecov](https://codecov.io/gh/rubberduck-vba/Rubberduck/pull/4418?src=pr&el=h1) Report > Merging [#4418](https://codecov.io/gh/rubberduck-vba/Rubberduck/pull/4418?src=pr&el=desc) into [next](https://codecov.io/gh/rubberduck-vba/Rubberduck/commit/f38ebf776c9de99883f2e3aca5e2291f0569bded?src=pr&el=desc) will **increase** coverage by `0.15%`. > The diff coverage is `56.03%`.
I'll download that installer at work tomorrow, and play with it in every way I can think of during lunch - if all goes well I'm good with merging it as-is.
> # [Codecov](https://codecov.io/gh/rubberduck-vba/Rubberduck/pull/4418?src=pr&el=h1) Report > Merging [#4418](https://codecov.io/gh/rubberduck-vba/Rubberduck/pull/4418?src=pr&el=desc) into [next](https://codecov.io/gh/rubberduck-vba/Rubberduck/commit/f38ebf776c9de99883f2e3aca5e2291f0569bded?src=pr&el=desc) will **increase** coverage by `0.28%`. > The diff coverage is `56.03%`.
> # [Codecov](https://codecov.io/gh/rubberduck-vba/Rubberduck/pull/4418?src=pr&el=h1) Report > Merging [#4418](https://codecov.io/gh/rubberduck-vba/Rubberduck/pull/4418?src=pr&el=desc) into [next](https://codecov.io/gh/rubberduck-vba/Rubberduck/commit/f38ebf776c9de99883f2e3aca5e2291f0569bded?src=pr&el=desc) will **increase** coverage by `0.28%`. > The diff coverage is `56.03%`.
> I just realized that this change has the added benefit that we no longer cache objects we change while parsing. More precisely, previously we had to worry about the references we save on the declarations. These got removed on the each load, whoch made it inherently unsafe to run tests in parallel. Now, this is a non-issue because we create the declarations each time anew from the cached command projects.