Type 'x' already defines a member called 'y' with the same parameter types

This forum is meant for questions and discussions about the X# language and tools
User avatar
baramuse
Posts: 84
Joined: Tue Nov 29, 2022 8:31 am
Location: France

Type 'x' already defines a member called 'y' with the same parameter types

Post by baramuse »

Hi,

I don't understand why XSC is giving me this error :

Code: Select all

Type 'DataDict' already defines a member called 'CheckStructure' with the same parameter types
Here is my code :

Code: Select all

METHOD CheckStructure() AS LOGIC
	RETURN SELF:CheckStructure(ARRAY<SYMBOL> {})

METHOD CheckStructure(server AS SYMBOL) AS LOGIC
	RETURN SELF:CheckStructure({ server })

METHOD CheckStructure( Liste AS ARRAY OF SYMBOL) AS LOGIC
...
Also, how could I declare "Liste" member as optional if I wanted to get rid of the empty function definition ? (If I can..)

Best regards.
User avatar
Chris
Posts: 4442
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Type 'x' already defines a member called 'y' with the same parameter types

Post by Chris »

Hi,

That's a bad error message (will open a compiler bug report on this), what it should say is that there's a CLIPPER and a STRICT method defined with he same name, and that's not allowed indeed. The reason why the first method is marked as CLIPPER calling convention is because you have enabled the /vo5 (Implicit CLIPPER calling convention) compiler option, which tells the compiler to treat methods with no parameters as such. Fortunately there's an easy fix for that, just declare the first method explicitly as STRICT.

METHOD CheckStructure() AS LOGIC STRICT

I did not understand what you mean with the second question, which and why is the empty function?
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
baramuse
Posts: 84
Joined: Tue Nov 29, 2022 8:31 am
Location: France

Re: Type 'x' already defines a member called 'y' with the same parameter types

Post by baramuse »

Thanks Chris for the explanation !

Second question was : how do I declare "Liste" parameter as optionnal, so I could get rid of the paramterless method and only have two overloads ?

Code: Select all

METHOD CheckStructure(server AS SYMBOL) AS LOGIC
	RETURN SELF:CheckStructure({ server })

METHOD CheckStructure(Liste AS ARRAY OF SYMBOL) AS LOGIC   <== how can I declare "Liste" as optional ?
User avatar
Chris
Posts: 4442
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Type 'x' already defines a member called 'y' with the same parameter types

Post by Chris »

Thanks, got it now! You can use a NULL default value for this, something like:

Code: Select all

METHOD CheckStructure(Liste := NULL AS ARRAY OF SYMBOL) AS LOGIC STRICT
	IF Liste == NULL
		? "NULL"
	ELSE
		? ALen(Liste)
	END IF
	RETURN TRUE
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
baramuse
Posts: 84
Joined: Tue Nov 29, 2022 8:31 am
Location: France

Re: Type 'x' already defines a member called 'y' with the same parameter types

Post by baramuse »

Chris wrote: Tue Jan 23, 2024 4:15 pm Thanks, got it now! You can use a NULL default value for this, something like:

Code: Select all

METHOD CheckStructure(Liste := NULL AS ARRAY OF SYMBOL) AS LOGIC STRICT
	IF Liste == NULL
		? "NULL"
	ELSE
		? ALen(Liste)
	END IF
	RETURN TRUE
Thanks but if I'd like to set its default to an empty array instead of a null is that possible ?
If not I can change the logic in the function to handle the list as null instead of empty.

Also shouldn't I check it with List IS NULL instead of List == NULL ?
Or maybe it's not supported by the compiler yet ?
User avatar
Chris
Posts: 4442
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Type 'x' already defines a member called 'y' with the same parameter types

Post by Chris »

baramuse wrote: Tue Jan 23, 2024 4:25 pm Thanks but if I'd like to set its default to an empty array instead of a null is that possible ?
If not I can change the logic in the function to handle the list as null instead of empty.
I don't think that's possible, because this requires a complex expression (array creation, even if empty) for the default value, and that's not allowed due to the way default values are implemented. Unless Robert has a smart idea that I'm not thinking of...

But why don't you do something like this instead:

Code: Select all

METHOD CheckStructure(Liste := NULL AS ARRAY OF SYMBOL) AS LOGIC STRICT
	IF Liste == NULL
		Liste := {}
	END IF
	? ALen(Liste)
baramuse wrote: Tue Jan 23, 2024 4:25 pm Also shouldn't I check it with List IS NULL instead of List == NULL ?
Or maybe it's not supported by the compiler yet ?
The IS keyword is different, it is used to compare against a type, if a variable or expression is of a certain type, like Liste IS ArrayList. In this case, you need to check if the variable has a value of NULL, so you need to use the equality operator.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
baramuse
Posts: 84
Joined: Tue Nov 29, 2022 8:31 am
Location: France

Re: Type 'x' already defines a member called 'y' with the same parameter types

Post by baramuse »

Also now I only have to overloads :

Code: Select all

CLASS DataDict
	METHOD MakeIndex( symServer AS SYMBOL, cFileName := NULL AS STRING)  AS LOGIC STRICT
		RETURN SELF:MakeIndex({symServer}, cFileName)

	METHOD MakeIndex( aServerListe := NULL AS ARRAY OF SYMBOL, cFileName := NULL AS STRING) AS LOGIC STRICT
	...
END CLASS
Compile fine.
But at execution time when I try to call

Code: Select all

var oDataDict := DataDict{}
oDataDict.MakeIndex(#Table1)
I have an exception :

Code: Select all

XSharp.Error
  HResult=0x80131500
  Message=Method is overloaded, Cannot determine the right overload to call.
  Source=XSharp.RT
User avatar
Chris
Posts: 4442
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Type 'x' already defines a member called 'y' with the same parameter types

Post by Chris »

About the exception, you can get this only if you do a late bound call, since this is a runtime error. The code in your sample (that uses var) is strongly typed, so it can't produce that error. Maybe the actual code is a bit different? If not, can you please post a full compilable code sample that I can compile here to have a look?

If you indeed need to do late bound calls though, it's gonna be tough with such overloads and especially default values, it's getting too complicated. So I'd suggest to keep things simple in the method definitions, or just use only strongly typed calls of course.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
baramuse
Posts: 84
Joined: Tue Nov 29, 2022 8:31 am
Location: France

Re: Type 'x' already defines a member called 'y' with the same parameter types

Post by baramuse »

baramuse wrote: Tue Jan 23, 2024 4:25 pm Also shouldn't I check it with List IS NULL instead of List == NULL ?
Or maybe it's not supported by the compiler yet ?
The IS keyword is different, it is used to compare against a type, if a variable or expression is of a certain type, like Liste IS ArrayList. In this case, you need to check if the variable has a value of NULL, so you need to use the equality operator.
[/quote]

Actually in the .net/C# world "obj is null" is being more and more used (even more with the "not null" as of c#9) because of the possibility of overloading the "==" operator rendering possibly wrong the "obj == null" check
It's been discussed here and there but here's a article just about that : https://medium.com/@erickgallani/the-di ... 3d955a639e
User avatar
baramuse
Posts: 84
Joined: Tue Nov 29, 2022 8:31 am
Location: France

Re: Type 'x' already defines a member called 'y' with the same parameter types

Post by baramuse »

Chris wrote: Tue Jan 23, 2024 4:57 pm About the exception, you can get this only if you do a late bound call, since this is a runtime error. The code in your sample (that uses var) is strongly typed, so it can't produce that error. Maybe the actual code is a bit different? If not, can you please post a full compilable code sample that I can compile here to have a look?

If you indeed need to do late bound calls though, it's gonna be tough with such overloads and especially default values, it's getting too complicated. So I'd suggest to keep things simple in the method definitions, or just use only strongly typed calls of course.
You're right the actual code is not exaclty that so I'll test a bit more with all the execution chain and I'll come back to you !
Post Reply