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
4
votes
6 answers
Why is this code giving an "unreachable code" error?
I can't seem to find a way to fix this problem. All i'm doing is declaring an integer and it's telling me that the code is unreachable.
private class myStack{
Object [] myStack = new Object[50];
private void push(Object a){
int…

user1078174
- 69
- 1
- 1
- 4
4
votes
3 answers
Unreachable code in for loop increment?
I'm getting a C4702: unreachable code warning in a for loop; the strange thing is that - by breaking apart the components inside the parens - the warning points to the increment part. Here's a sample program that demonstrates this error:
int…

congusbongus
- 13,359
- 7
- 71
- 99
4
votes
3 answers
Why Java identifies unreachable code only in case of while loop?
If I have code like
public static void main(String args[]){
int x = 0;
while (false) { x=3; } //will not compile
}
compiler will complaint that x=3 is unreachable code but if I have code like
public static void main(String args[]){
…

Aniket Thakur
- 66,731
- 38
- 279
- 289
4
votes
3 answers
Why is the code in my foreach unreachable? (Exact copy of working code thats been Unit tested)
The code below is an exact copy of code that's working perfectly. The difference is that this code is being placed in a WCF Service Application Project whereas the working code is from a Windows Forms Application Project. The code in the foreach is…

Zubair
- 107
- 2
- 12
3
votes
3 answers
Can the gnat compiler find unused specification procedures/functions/variables?
Is there a warning option switch that will identify spec-level procedures, functions, or variables that are not called or referenced anywhere? I've tried the switches below without luck.
This is what I'm currently using:
-gnatwfilmopuvz
-- m …

Douglas E
- 31
- 1
3
votes
2 answers
What happen when program reach unreachable on ReleaseFast? (Zig lang)
I read on Zig Doc it has undefined behavior. is that it? isn't there any way tho predict the behavior of the code after hitting unreachable?
like if it's process next line or try to continue like unreachable never been there!

Sarvarian
- 43
- 5
3
votes
1 answer
Why does this code warned unreachable in Groovy?
I was thinking to return a map with several directories list. But the very first caused a warning for me:
def enlistFiles() {
return
[downloadFolder: downloadFolder.listFiles( new FileFilter() {
@Override
boolean…

Dims
- 47,675
- 117
- 331
- 600
3
votes
3 answers
Visual Studio marks code just after "case variable:" unreachable
I have a switch statement with multiple cases:
ConversionState state = ConversionState.Start; // enum
for(int i = 0; i < source.Length; i ++)
{
switch(state)
{
case ConversionState.Start:
state = ConversionState.Name; //…

sisisisi
- 481
- 7
- 17
3
votes
1 answer
Can a java compiler optimize this code away?
Is a java compiler or runtime ( or any other language compiler ) smart enough to realize branch 3 can never happen , and optimize it away? I've seen this kind of "defensive programming" with many beginning developers, and wonder if this dead weight…

Gonen I
- 5,576
- 1
- 29
- 60
3
votes
5 answers
Unreachable code detected C# (absolute beginner)
Could you explain how should I avoid this warning: "Unreachable code detected" in Visual Studio 2010 Express ? I'm learning C# from a manual.
It's an exercise for creating a simple method. I'm entering the example precisely as written in the book.…

user3190322
- 31
- 2
2
votes
1 answer
Flutter Application works flawless on debug build but fails to build as release
I need your help.
I recently started with flutter and until now, everything went fine without any problems. But suddenly, when I tried to build the appbundle or the apk for --release, there are some weird errors…

Florian Groß
- 21
- 6
2
votes
1 answer
Unreachable code in simple arithmetic function
Upon compile, SBCL complains that (mod number 10) is unreachable in
(defun foo (number)
(cond
((> number 10) (mod number 10))
(t number)))
Why is this so?
The full compiler message:
; in: DEFUN FOO
; (MOD NUMBER 10)
; --> LET IF AND…

alcorn
- 1,268
- 1
- 8
- 17
2
votes
2 answers
How this switch case has unreachable code?
I was implementing some generic IEqualityComparer Equal() method when the code in the switch is unreachable without visible reason for me:
public bool Equals(T x, T y)
{
switch (nameof(T))
{
case nameof(Accessory):
…

Eugene
- 217
- 8
- 24
2
votes
1 answer
Why does sonar think this scala code is unreachable
I have a Scala method for which SonarLint (IntelliJ plugin version 3.2.1.2406) is flagging the return statement as 'Unreachable code'. For the purposes of this example I've removed the actual logic and replaced with printlns, but it produces the…

Mike
- 21
- 2
2
votes
4 answers
java anonymous inner class unreachable code
Java compiler complains when you write a code that is unreachable. For example
public void go()
{
return;
System.out.println("unreachable");
}
However, when you define a new method in an anonymous class which cannot be reached from…

kioto
- 93
- 1
- 4