# Unreachable code warning

**URL:** https://forum.servoy.com/t/unreachable-code-warning/16854
**Category:** Classic Servoy
**Created:** [December 17, 2012, 5:59pm UTC](https://forum.servoy.com/t/unreachable-code-warning/16854 "2012-12-17T17:59:55Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jgarfield](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@jgarfield](https://forum.servoy.com/u/jgarfield)
#### Post date: [December 17, 2012, 5:59pm UTC](https://forum.servoy.com/t/unreachable-code-warning/16854/1 "2012-12-17T17:59:55Z")

</div>

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

Take for example the following function

```auto
/**
 * @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](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.

---

<div class="post-metadata">

### Author: ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)
#### Post date: [December 17, 2012, 6:51pm UTC](https://forum.servoy.com/t/unreachable-code-warning/16854/2 "2012-12-17T18:51:24Z")

</div>

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:

```auto
if(true) return oException;

```

Agree, this shouldn’t be necessary, but works as good as surpress warnings ![:)]( "Smile")

---

<div class="post-metadata">

### Author: ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)
#### Post date: [December 17, 2012, 6:54pm UTC](https://forum.servoy.com/t/unreachable-code-warning/16854/3 "2012-12-17T18:54:01Z")

</div>

> 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’?

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

```

---

<div class="post-metadata">

### Author: ![jgarfield](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@jgarfield](https://forum.servoy.com/u/jgarfield)
#### Post date: [December 17, 2012, 7:14pm UTC](https://forum.servoy.com/t/unreachable-code-warning/16854/4 "2012-12-17T19:14:28Z")

</div>

> mboegem:  
> you mean like your ‘@return’?

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

- @param {Object} args

```auto

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);  
}  
}

```auto

```

---

<div class="post-metadata">

### Author: ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)
#### Post date: [January 2, 2013, 4:04pm UTC](https://forum.servoy.com/t/unreachable-code-warning/16854/5 "2013-01-02T16:04:14Z")

</div>

[http://git.eclipse.org/c/dltk/org.eclip … a689755595](http://git.eclipse.org/c/dltk/org.eclipse.dltk.javascript.git/commit/?id=b4ab9044fffd855ee36d0be909a60aa689755595)

---

<div class="post-metadata">

### Author: ![jgarfield](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@jgarfield](https://forum.servoy.com/u/jgarfield)
#### Post date: [January 2, 2013, 4:47pm UTC](https://forum.servoy.com/t/unreachable-code-warning/16854/6 "2013-01-02T16:47:10Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)
#### Post date: [January 2, 2013, 4:49pm UTC](https://forum.servoy.com/t/unreachable-code-warning/16854/7 "2013-01-02T16:49:18Z")

</div>

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