xsharp.eu • Error XS9040 The type of the first ASSIGN parameter must match the returntype...
Page 1 of 2

Error XS9040 The type of the first ASSIGN parameter must match the returntype...

Posted: Mon Mar 02, 2020 10:58 pm
by ic2
With the last Fox version I resumed my conversion work, by re-running the XPorter on my VO library. I get this error on some code to read/write the registry:
Error XS9040 The type of the first ASSIGN parameter must match the returntype of the ACCESS.
I would say it does? Below the code:

In the class:
PROTECT hKeyP AS PTR
Returntype and parameter are PTR's ....

Dick

ACCESS hKey STRICT
RETURN SELF:hKeyP

ASSIGN hKey( ptr_hKey AS PTR ) AS PTR STRICT

IF ( ptr_hKey == HKEY_CLASSES_ROOT .OR. ;
ptr_hKey == HKEY_CURRENT_USER .OR. ;
ptr_hKey == HKEY_LOCAL_MACHINE .OR. ;
ptr_hKey == HKEY_USERS .OR. ;
ptr_hKey == HKEY_CURRENT_CONFIG .OR. ;
ptr_hKey == HKEY_DYN_DATA ;
)

SELF:hKeyP := ptr_hKey

ELSE
// Default standard key:
SELF:hKeyP := HKEY_LOCAL_MACHINE
ENDIF

RETURN SELF:hKeyP

Error XS9040 The type of the first ASSIGN parameter must match the returntype...

Posted: Tue Mar 03, 2020 12:26 am
by Chris
Hi Dick,

The ASSIGN has a PTR param, while the ACCESS is untyped, so it returns a USUAL. Type the access AS PTR STRICT and it should be fine.

Error XS9040 The type of the first ASSIGN parameter must match the returntype...

Posted: Tue Mar 03, 2020 11:35 am
by ic2
Hello Chris,

Of course! I was so concentrated on SELF:hKeyP, PTR in both, that I missed that the access was actually untyped.

Adding AS PTR STRICT indeed solved it, thanks.

Dick

Error XS9040 The type of the first ASSIGN parameter must match the returntype...

Posted: Tue Mar 03, 2020 2:27 pm
by g.bunzel@domonet.de
Hello Chris,

in VO an ASSIGN should never return a value - if I remember right an info from Robert. Then the assign should be
ASSIGN hKey (ptr_hKey AS PTR) AS VOID STRICT. So the return values ​​of ASSIGN and ACCESS are not equal. Is this a problem in X#?

Thanks in advance.

Best regards

Gerhard

Error XS9040 The type of the first ASSIGN parameter must match the returntype...

Posted: Tue Mar 03, 2020 4:22 pm
by wriedmann
Hi Gerhard,
X# translates the access/assign pair to a .NET property.
One of the prerequisites of the property is that the getter part has to return the same datatype as the setter part accepts, and the setter part has no return type.
So the correct access/assign pair in X# is for example:

Code: Select all

assign hKey( ptrKey as ptr ) as void 
return _ptrKey
access hKey as ptr
return _ptrKey
In X# the relative code will look like this (short form)

Code: Select all

property hKey as ptr get _ptrKey set _ptrKey := value
Wolfgang

Error XS9040 The type of the first ASSIGN parameter must match the returntype...

Posted: Tue Mar 03, 2020 4:51 pm
by Chris
Hi Gerhard,

As Wolfgang explained, param type of ASSIGN = return type of ACCESS. Indeed, ASSIGNs do not return anything in .Net.

Error XS9040 The type of the first ASSIGN parameter must match the returntype...

Posted: Tue Mar 03, 2020 4:59 pm
by FFF
Chris wrote:As Wolfgang explained, param type of ASSIGN = return type of ACCESS. Indeed, ASSIGNs do not return anything in .Net.
Out of curiosity: Does anyone know, WHY this is so? I could understand, that MS thought this not essential, but why explicitely forbid a return value?

Error XS9040 The type of the first ASSIGN parameter must match the returntype...

Posted: Tue Mar 03, 2020 5:05 pm
by g.bunzel@domonet.de
Hi Wolfgang and Chris,

thanks for the clarification.

Gerhard

Error XS9040 The type of the first ASSIGN parameter must match the returntype...

Posted: Tue Mar 03, 2020 5:11 pm
by robert
Karl,

Try this in VO:

Code: Select all

CLASS Bar
    PROTECT Value AS LONG
ASSIGN Foo(nNewValue)  CLASS Bar
    SELF:Value := nNewValue
    RETURN nNewValue *2
ACCESS Foo CLASS Bar
   RETURN SELF:Value
FUNCTION Start
    LOCAL oBar AS Bar
    oBar := Bar{}
    ? oBar:Foo := 10
    WAIT
    RETURN NIL
What do you think will be shown as the result of the assignment ?
And is the access called (try to set a break point there) ?

Robert

Error XS9040 The type of the first ASSIGN parameter must match the returntype...

Posted: Tue Mar 03, 2020 5:42 pm
by FFF
Robert,
thx, that's short and clear - yes, it won't access the access.;-)
@Gerhard, sorry for capering your thread...