Confusing Error "Several Items with this Name"

(Hopefully this tale will help someone else out in future.)

I’ve got a project from REALbasic days which I’m updating for Xojo.

Within this project I have an class on a window.

When I go to compile, Xojo would throw an error

Location: winMain.Open Issue: There are several items with this name and it is not clear which one the call refers to mathEngine=new mathClass.

I tried changing the name of the property and commenting out all of the code which references it. I tried removing the property from the window and adding it back again. The only thing which fixed the issue is to remove the class from the window. This obviously wasn’t an acceptable solution.

Eventually I discovered that the class had two Constructor methods. Constructor(equation as string = “”) had code in it, and Constructor() had no code in it. I removed the Constructor() event, the project compiled and ran just fine. It’s obvious looking at the two Constructor methods why the compiler was throwing that error, but the error code gave no indication that’s where the problem was.

Thank you.

Thanks for posting this Thomas. I’m just getting around to updating one of my applications and I’m getting this error as well, but with dictionaries. The following throws that error:

someListBox.AddRow(globalDictionary(0).Value("theKey"))

However, if I do the following it’s fine:

someVar = globalDictionary(0).Value("theKey")
someListBox.AddRow(someVar)

[quote=70282:@Eric Andrews]Thanks for posting this Thomas. I’m just getting around to updating one of my applications and I’m getting this error as well, but with dictionaries. The following throws that error:

someListBox.AddRow(globalDictionary(0).Value("theKey"))

However, if I do the following it’s fine:

someVar = globalDictionary(0).Value("theKey") someListBox.AddRow(someVar) [/quote]
Listbox add row has a bunch of forms and thats whats ambiguous here

Because
globalDictionary(0).Value(“theKey”) returns a variant
it COULD be either the form of add row in use

Try

someListBox.AddRow(globalDictionary(0).Value("theKey").StringValue)

Since you can only put strings in the listbox anyways

Thanks for posting that explanation Norman. Of course that makes sense. The error message makes it kind of hard to figure out.

Well the error message does highlight the thing that is wrong where it can.
It does try to point you to “Addrow” being ambiguous in a case like this.

A read of the docs shows you there are several forms - now the question is WHY is the way you’re using it ambiguous.
That part is where a better message would be useful as the compiler should be able to tell you why something is ambiguous - it just doesn’t at present.

So IF you run into situations like this again the first thing to do is definitely look at the method in use & see if there are several overloaded forms. If so, have you used it in a way that one or more of the forms would / could be considered legitimate or correct in this context. If so, you have your answer.

Sure, that understandable. For me, the error message just doesn’t seem clear as to a potential incompatibility between method and parameter. If it were something like “expected a string, but got integer” then that would be easier to understand. Does this error ever happen outside of using variants?

Yes
It can - even in your own creations

Try something like this
In a module write a few methods with the signatures

DoStuff( i as integer)
DoStuff(i as single)

then somewhere else try and use it with

DoStuff(1.0)

The reason ?
1.0 is a double
To use DoStuff(integer) would be one conversion (from double to integer)
To use DoStuff(single) would be one conversion (from double to single)

So since they both require one conversion its not clear which is “better” so the compiler gives an error

[quote=71194:@Norman Palardy]Yes
It can - even in your own creations

Try something like this
In a module write a few methods with the signatures

DoStuff( i as integer)
DoStuff(i as single)

then somewhere else try and use it with

DoStuff(1.0)

The reason ?
1.0 is a double
To use DoStuff(integer) would be one conversion (from double to integer)
To use DoStuff(single) would be one conversion (from double to single)

So since they both require one conversion its not clear which is “better” so the compiler gives an error[/quote]
This is a very good explanation.