Why is this marked as unreachable code?

function IntToPrefab (n : int) {
switch (n) {
case 1:
return blockPrefab;
case 2:
return lightHardBlockPrefab;
case 3:
return arrowBlockPrefab;
case 4:
return tripleArrowBlockPrefab;
case 5:
return nonRegenBlockPrefab;
case 6:
return darkBlockPrefab;
case 7:
return darkHardBlockPrefab;
case 8:
return darkArrowBlockPrefab;
case 9:
return darkTripleArrowBlockPrefab;
case 10:
return torchPrefab;
case 11:
return playerPrefab;
case 12:
return enemyPrefab;
case 13:
return entrancePrefab;
case 14:
return bonusEntrancePrefab;
case 15:
return goldPrefab;
}
return null;
}

Besides the annonying spam of warnings every time I compile my scripts, this code is working as intended. Can I turn the warnings off somehow?

This is a known compiler complaint Unity throws from switch blocks where you return before any manner of break statement. The only ways I know to avoid the warning are

  1. assign a temp variable and return that at the end of the function
  2. use a prefabArray[] for those objects and return by index like the function is doing

Old Unity Forum Thread

Have you tried rewriting it with the "standard" syntax of the switch clause? Of course your code is correct, but maybe the compiler prefers to read it this way.

var obj;
switch(n)
{
  case 1:
    obj = blockPrefab;
    break;
  case 2:
    obj = lightHardBlockPrefab;
    break;
  default:
    obj = null;
}
return obj;