__objAddData() fails if symbol name == class name

82 views
Skip to first unread message

Klas Engwall

unread,
May 14, 2021, 6:05:21 PM5/14/21
to harbou...@googlegroups.com
Hi,

The Google Groups software sent a moderation alert message regarding a
post by Victor Casajuana Mas, but when I logged in to release it, it was
no longer there. Based on the content of the alert message I thought
Victor's bug report looked legitimate, so I played with his test code
and came up with a version that maybe shows a little more clearly what
happens.

The starting point was that Victor created a class with no instance
variables to begin with, and then he added a couple of variables with
__objAddData().

The name of one of the instance variables was identical to the name of
the class where he tried to insert it. This kind of naming scheme works
just fine if the variable is declared in the class from the beginning.
But it fails silently if the variable is instead added to an already
instantiated class with __objAddData(). The following code snipped shows
the failure. I doubt that this behavior is intentional, but if it is
supposed not to work, shouldn't there be an RTE instead of a silent failure?

Regards,
Klas

//-------------------------------------
#include 'hbclass.ch'

procedure Main()

local oTest := Test1():New()

__objAddData( oTest, "Test1" )
__objAddData( oTest, "Test2" )

? " Test1", __objHasMsg( oTest, "Test1" ) // .T.
? "_Test1", __objHasMsg( oTest, "_Test1" ) // .F. This seems suspicious
? " Test2", __objHasMsg( oTest, "Test2" ) // .T.
? "_Test2", __objHasMsg( oTest, "_Test2" ) // .T.

return


CREATE CLASS Test1

EXPORTED:
METHOD New() CONSTRUCTOR

ENDCLASS

METHOD New() Class Test1
return self
//-------------------------------------

Bacco

unread,
May 14, 2021, 7:49:36 PM5/14/21
to harbour-devel
I still have this in the notification mail I received too:

From: Victor Casajuana Mas <victorcas...@gmail.com>
To: Harbour Developers <harbou...@googlegroups.com>
Cc: 
Bcc: 
Date: Fri, 14 May 2021 01:49:05 -0700 (PDT)
Subject: __objAddData() don't function correctly
Hello

This code don't function, breaks in oTest:Test := 'Test' because __objAddData() don't create a data in a class that the name of class is the same that de new data.

#include 'hbclass.ch'
Function Main()

    oTest := Test():New() 
    __objAddData( oTest, "Var1" )
    __objAddData( oTest, "Test" )

    oTest:Var1 := 'Var1'
    otest:Test := 'Test'

    ?oTest:Var1
    ?oTest:Test

Return ( Nil )

CREATE CLASS Test

    EXPORTED:
        METHOD New() CONSTRUCTOR

ENDCLASS

METHOD New() Class Test
Return ( Self )

Any solution?

This code works fine, but I defined DATA in a Class Definition.

#include 'hbclass.ch'

Function Main()

    oTest := Test():New() 
    __objAddData( oTest, "Var1" )

    oTest:Var1 := 'Var1'
    otest:Test := 'Test'

    ?oTest:Var1
    ?oTest:Test

Return ( Nil )

CREATE CLASS Test

    EXPORTED:
        METHOD New() CONSTRUCTOR
        
        DATA Test AS CHARACTER Init ''

ENDCLASS

METHOD New() Class Test
Return ( Self )

(at first glance it seems to me as an usage feature, but in case it's a bug or undesired feature, here it is)
Reply all
Reply to author
Forward
0 new messages