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

This forum is meant for questions and discussions about the X# language and tools
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

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

Post 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
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

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

Post 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.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

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

Post 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
g.bunzel@domonet.de
Posts: 97
Joined: Tue Mar 01, 2016 11:50 am
Location: Germany

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

Post 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
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

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

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

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

Post by Chris »

Hi Gerhard,

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

XSharp Development Team
chris(at)xsharp.eu
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

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

Post 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?
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
g.bunzel@domonet.de
Posts: 97
Joined: Tue Mar 01, 2016 11:50 am
Location: Germany

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

Post by g.bunzel@domonet.de »

Hi Wolfgang and Chris,

thanks for the clarification.

Gerhard
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

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

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

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

Post by FFF »

Robert,
thx, that's short and clear - yes, it won't access the access.;-)
@Gerhard, sorry for capering your thread...
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Post Reply