Unreachable code warning

So I believe I’ve found a hole in the warning checking code.

Take for example the following function

/**
 * @param {String} sMethodName
 * @param {Object} args
 * 
 * @return {type:<String>, message:<String}}
 * 
 * @properties={typeid:24,uuid:"5F5DC945-928A-4C3E-A582-CDC5528D060F"}
 */
function MissingArgument(sMethodName, args) {
	var oException = {
		type	:	"MissingArgument",
		message	:	"Required arguments were not passed to " + sMethodName + " at index " + emptyIndexes(args)
	}
	
	return oException;
	
	//Finds empty indexes in the arguments object
	function emptyIndexes(arg) {
		
		/** @type {Array} */
		var aArg = Array.prototype.slice.call(arg);
		
		var aIndex =  aArg
			.map(function (element, index){
				if (element === null || element === undefined)
				{
					return index;
				}
				else
				{
					return null;
				}
			})
			.filter(function (element){
				return element != null
			})
		return aIndex;
	}
	
}

I’m getting an unreachable code warning on my helper function “emptyIndexes”. Technically speaking, because of JavaScript function hoisting this is an incorrect warning. Having helper functions after the return is a fairly common pattern used to reduce clutter in the main body of a function and is one of the prime benefits of hoisting.

I’ve searched around (notably http://wiki.servoy.com/display/public/DOCS/Annotating+JavaScript+using+JSDoc) for how to add a @SuppressWarnings for this particular error, but I can’t find what the right argument to it would be, and there is no Quick Fix option that tells me what it would be.

Ultimately I think it would be better if this was correctly not counted as unreachable, but if I was able to specifically suppress these warnings when needed that would be good in the interim.

Edit: Incidentally I also can’t figure out what the proper @param type is for when you are passing an “arguments” type object.

Hi James,

As you probably found out yourself: moving the helperfunction above your code will solve the warning.

If you want to leave it at the bottom, you can prevent the warning to write your return as:

if(true) return oException;

Agree, this shouldn’t be necessary, but works as good as surpress warnings :)

jgarfield:
Edit: Incidentally I also can’t figure out what the proper @param type is for when you are passing an “arguments” type object.

you mean like your ‘@return’?

@return {{type:String, message:String}}

mboegem:
you mean like your ‘@return’?

No, I mean the parameter type of the “args” argument ```

  • @param {Object} args

This particular code is used to throw a missing argument exception, and part of the message it generates is which arguments are missing, requiring that you pass in the arguments object from your excepting method

e.g.

function example(sName, nValue) {
if (! (sName && nValue) ) {
throw scopes.exceptions.MissingArgument(“example”, arguments);
}
}

http://git.eclipse.org/c/dltk/org.eclip … a689755595

Awesome!
So this should just come in naturally when we update eclipse at some point, right?

When you update servoy, maybe even in 6.1.4 because there are a few changes that we need for that release.