Problem with warnings in 7.4.1 (JSDoc?)

Hi,

I have recently upgraded to V7.4.1 and immediately got a lot of new warnings for my project regarding invalid arguments similar to:

The method sendMaill(String,String,String,String,String,String,Array<plugins.mail.Attachment>,String) in the type Plugin<mail> is not applicable for the arguments (String,String,String,String,String,String,plugins.mail.Attachment|Array<plugins.mail.Attachment>)

The one thing they all have in common is that there are multiple calling options for the method and the particular one I am using is definitely valid for the method in question. Further investigation shows that there are two conditions that need to be met for the warning to show up incorrectly:

  1. There must be a signature matching the call you are using but with additional arguments at the end
  2. The particular signature you are using comes after the one it complains about when you look at the code completion options

This would indicate that Servoy/Eclipse/JSDoc (not sure which is responsible) is finding the partial match for call and then immediately reporting the warning without checking the rest of the possible calling options.

Has anyone else experienced this? Should I report it as a bug?

Thanks
Steve

steve1376656734:
plugins.mail.Attachment|Array<plugins.mail.Attachment>

This is the problem, you casted a variable to be either one or the other type.
Just cast it as below and you should be good.

Array<plugins.mail.Attachment>

Hi Marc,

I understand what you are saying and can see that all the warnings are related to functions that have at least one parameter that has been declared as multiple types. The problem I have now is that I’m not sure how to overcome it. My scenario is I am calling the plugins.mail.sendMail function that has multiple signatures two of which are:

plugins.mail.sendMail(String,String,String,String,String,String,plugins.mail.Attachment) plugins.mail.sendMail(String,String,String,String,String,String,Array<plugins.mail.Attachment>)

The final argument can be either a single attachment or an array of attachments. I have an intermediate routine that takes the same parameters and manipulates some of them prior to calling the plugins.mail.sendMail function and has been declared as follows:

/**
 * @param {String} param1
 * @param {String} param2
 * @param {String} param3
 * @param {String} param4
 * @param {String} param5
 * @param {String} param6
 * @param {plugins.mail.Attachment|Array<plugins.mail.Attachment>} param7
 */
function myFunc(param1, param2, param3, param4, param5, param6, param7) {
    // Do some stuff with params 1 - 6 (nothing with param 7)
    // ....
    // ....

    // Now call the mail plugin
    plugins.mail.sendMail(param1, param2, param3, param4, param5, param6, param7);
}

How can I modify my intermediate routine to avoid the warning as I cannot explicitly cast the last parameter as it could have been passed as either type?

The weird thing is I never got these warnings with 7.3!

Many thanks
Steve

Hi Steve,

you could something like this at the top of your function:

/** @type {Array<plugins.mail.Attachment>} */
var myAttachments = [];
if(param7 !== undefined) {
     if(param7 instanceof Array) {
          myAttachments = param7;
    }  else {
          myAttachments.push(param7);
    }
}

Now pass the myAttachments variable to the plugin function instead of directly passing param7.

Hi Marc,

Tried your suggestion and unfortunately it just moved the warning to the myAttachments.push(param7) line. However it did point me to a solution that does remove all the warnings which is:

/** @type {Array<plugins.mail.Attachment>} */
var myAttachments = [];
if(param7 !== undefined) {
     if(param7 instanceof Array) {
          myAttachments = param7;
    }  else {
          /** @type {plugins.mail.Attachment} */
          var tempAttachment = param7;
          myAttachments.push(tempAttachment);
    }
}

This does seem rather convoluted though just to avoid a warning :?

Thanks for your help
Steve

Hi Steve,

steve1376656734:
This does seem rather convoluted though just to avoid a warning :?

I think there is a learning moment here.
If you know for a fact your code is right AND efficient and the parser spouts out a warning that is clearly wrong, DON’T try to fix it and make it less efficient JUST to make the parser happy.
Ignore the warning and file it as a bug, the warning hopefully will be going away in the next version(s).

And as I have said in many other posts. Warning are just that, warnings. Not errors. Your code will not work any worse (in 99.999% of the cases). Usually the parser is right and there is indeed something going on but sometimes it is clearly just WRONG. So ignore it and move on (and file it as a bug report).

Just my 2 cents.

Hi Robert,

Great advice and after more than 30 years in the business I find learning moments still happen every day :D

That said I’m very picky and hate to see warnings in my code :x

Steve

ROCLASI:
Ignore the warning and file it as a bug, the warning hopefully will be going away in the next version(s).

I’m pretty sure declarations of variables typed as ‘type A OR type B’ can’t be parsed correctly.
(If I’m recalling the statement of Johan Compagner correctly)

steve1376656734:
Tried your suggestion and unfortunately it just moved the warning to the myAttachments.push(param7) line.

Sorry Steve, my bad wrote this without consulting my own parser. :-)

steve1376656734:
This does seem rather convoluted though just to avoid a warning

I agree, though the only way to really avoid the ‘OR’ type you use is just to always pass an Array of attachments to your method.

mboegem:
I agree, though the only way to really avoid the ‘OR’ type you use is just to always pass an Array of attachments to your method.

Doh! - why didn’t I think of that. The simple solutions are always the best :D

this:

/**
* @param {String} param1
* @param {String} param2
* @param {String} param3
* @param {String} param4
* @param {String} param5
* @param {String} param6
* @param {plugins.mail.Attachment|Array<plugins.mail.Attachment>} param7
*
 * @properties={typeid:24,uuid:"7BF7C4E7-C7EA-45F0-A607-32C750FBB9CC"}
 */
function myFunc(param1, param2, param3, param4, param5, param6, param7) {
    plugins.mail.sendMail(param1,param2,param3,param4,param5,param6,param7)
}

should work in the coming release. (at least if i try it now it works for me)