BUG?: Switch statement with returns works but gives Code Unreachable warning.

Sample code (on a Behaviour for convenience):

function Start() {
	Debug.Log(BrokenSwitch(0));
	Debug.Log(BrokenSwitch(1));	
}

function BrokenSwitch(i:int){
	switch (i) {
		case 0: return "a";	
		case 1: return "b";	
	}
}

Gives the warning message:
Assets/Scripts/Test.js(7,9): BCW0015: WARNING: Unreachable code detected.

However output of that code shows that it does reach both code branches, output:

a
UnityEngine.Debug:Log(Object)
Test:Start() (at Assets/Scripts/Test.js:2)
b
UnityEngine.Debug:Log(Object)
Test:Start() (at Assets/Scripts/Test.js:3)

Of course you can fix it with a construct like:

function NotBrokenSwitch(i:int){
	var s:String;
	switch (i) {
		case 0: s = "a"; break;
		case 1: s = "b"; break;
	}
	return s;
}

But it seems that the first should not have a warning either.

Seems like a bug to me. Tested it here, and I thought it’d maybe have something to do with missing breaks. And I’m not too sure whether a return is correct in a switch, but the unreachable code-warning to me seems like a bug.

Without break statements, it should be giving you that warning. In case 0, it sees “return a; return b;”, and since it can’t get to return b, that’s unreachable code.
If you put “break;” after each case block, it shouldn’t give the warning anymore.

I tried that Vicenti, didn’t make a difference. That’s the odd part, still getting the warnings.

@Vinceti your point is clear however I’ve never come across a compiler that has given that as an error before (although I’m not sure I’ve used that construct a heap of times). Generally a return statement seems to be considered an implicit break.

And as Jordi says it’s still a warning; presumably because the break becomes unreachable.