Unreachable code is part of the source code of a program which can never be executed because there exists no control flow path to the code from the rest of the program.
Questions tagged [unreachable-code]
181 questions
1
vote
0 answers
Why backticks are required when matching Strings in Scala?
So I had an error where a match expression always yielded unreachable cases looking like this.
class KeyControl(left: String, right: String, up: String, down: String){
def direction(key: String): (Int, Int) = {
key match{
case left =>…

Tarmiac
- 846
- 1
- 8
- 14
1
vote
1 answer
What is the most graceful way to write unreachable else block
For example. (in Pseudo language)
if ( a == 1 || a == 2 || a == 3 ) {
... some unrelated pre handling ...
if (a == 1) {
...
} else if( a == 2) {
...
} else if( a == 3) {
...
} else {
///////////// this is the…

osexp2000
- 2,910
- 30
- 29
1
vote
0 answers
MISRA checker wrong Inferring after passing pointer to function
Somewhere in my project I have this code:
{
uint8_t u8Integer = 0xFFU;
returnCode = someFucntion(&u8Integer);
uint8_t u8Decimal = 0xFFU;
returnCode = someOtherFucntion(&u8Decimal);
uint16_t u16Temp =…

Ivan
- 1,352
- 2
- 13
- 31
1
vote
2 answers
Warning: Unreachable code, Unused equals expression in Kotlin
Here is my code, I don't like warnings.
currentFlag.inc() is making warning: unreachable code, if(currentFlag == 1) is making warning: unused equals expression
private fun processGather() {
TODO("process Gather implemented")
…

Creative IT Team
- 13
- 2
- 3
1
vote
1 answer
Verilog Synthesis Error (Synth 8-151): Case item is unreachable
I'm writing a Verilog module for a simple FSM that has 6 possible states. The module has 4 Moore outputs and 7 inputs from other modules. I'm using a case statement to determine the next value of the state however I'm getting the synthesis…
user14173380
1
vote
2 answers
Output Console freeze after entering the input
I have been trying to code to find the LCM of given Array elements. My code looks like this
public long LcmOfArray(List a)
{
long LCM = 1;
bool divisible = false;
int divisor = 2, count = 0;
while (count != a.Count)
{
…

Saranya
- 69
- 1
- 4
1
vote
2 answers
Throwing temporary exceptions without "unreachable code detected"
When writing code, I'll quite often temporarily inject random exceptions to ensure error flow is as expected.
eg
public void SomeFunc()
{
Console.WriteLine("Some code");
throw new Exception("BOOOOM!"); //added temporarily
…

GazTheDestroyer
- 20,722
- 9
- 70
- 103
1
vote
2 answers
Why is this program showing "unreachable code" warning? And how do I suppress it?
#include
#include
#include
void function(void);
int main(void)
{
clrscr();
int ch;
while(1)
{
cin>>ch;
if(ch==2)
exit(0);
else
function();
}//while
return 0;
}//main
void function(void)
{
…

Shashank Kadambri
- 15
- 1
- 7
1
vote
3 answers
Java For Loop Unreachable Code
I have a for loop in my code that's giving an error on the entire loop itself, saying it's "unreachable code". I'm completely unsure about what's causing this with this loop:
public ArrayList Update(ArrayList addInputs)
{
// stores…

Joseph Oliver
- 169
- 1
- 12
1
vote
1 answer
I get an Unreachable code error when I run this but I don't know why
I have an assignment where I need to create a game that lets you move a piece around a 10x10 board. You move to the "^" space and you win. This is the code I have so far but I'm having problems with it. I put a break in the code for when the player…

NickH
- 21
- 1
- 4
1
vote
1 answer
Is there a standard way to mark unreachable points in Java code?
Per the Java Language Specification Java SE 8 Edition, §14.21 Unreachable Statements:
It is a compile-time error if a statement cannot be executed because it is unreachable.
The Standard goes on to define precisely what reachable/unreachable and…

Daniel Trebbien
- 38,421
- 18
- 121
- 193
1
vote
1 answer
Reduce visibility of classes and methods
TL;DR: Given bytecode, how can I find out what classes and what methods get used in a given method?
In my code, I'd like to programmatically find all classes and methods having too generous access qualifiers. This should be done based on an…

maaartinus
- 44,714
- 32
- 161
- 320
1
vote
6 answers
Why can I compile a code with 2 returns?
Since am comming from a java island, I wounder why the compiler doesnt warns about unreachable code in something like:
int main(int argc, char** argV)
{
std::list lst = {1,2,3,4};
return 0;
std::cout << "Done!!!" << std::endl;
…

Firewall-Alien
- 123
- 7
1
vote
3 answers
Dynamically display an image url with javascript
I am using tag manager to dynamically place information from the website into an html element using custom javascript. My code at the moment is this. PS I can't figure out how to post properly. This actually starts with
function(){
…

Matty2Shoes
- 11
- 1
- 7
1
vote
2 answers
For Loops Java Unreachable Statement
I keep getting an error thrown at the line that I have put a comment above the line that says "unreachable statement." How can I fix this? Is there anything else wrong with this code?
boolean containsAll(IntSet [] s) {
return false;
//…

gracei
- 11
- 2