Skip to content

Commit b3ac9ae

Browse files
committed
Merge pull request #2025 from sjamesr/continue_fixups
fix 'continue not in a loop' inspector
2 parents d4ac7fb + a58f2b0 commit b3ac9ae

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/com/goide/inspections/GoContinueNotInLoopInspection.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.goide.psi.GoContinueStatement;
2020
import com.goide.psi.GoForStatement;
21+
import com.goide.psi.GoFunctionLit;
2122
import com.goide.psi.GoVisitor;
2223
import com.goide.psi.impl.GoElementFactory;
2324
import com.intellij.codeInspection.*;
@@ -39,9 +40,9 @@ protected GoVisitor buildGoVisitor(@NotNull final ProblemsHolder holder, @NotNul
3940
return new GoVisitor() {
4041
@Override
4142
public void visitContinueStatement(@NotNull GoContinueStatement o) {
42-
if (PsiTreeUtil.getParentOfType(o, GoForStatement.class) == null) {
43-
holder.registerProblem(o, "Continue statement not inside a for loop.", ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
44-
new ReplaceWithReturnQuickFix());
43+
if (!(PsiTreeUtil.getParentOfType(o, GoForStatement.class, GoFunctionLit.class) instanceof GoForStatement)) {
44+
holder.registerProblem(o, "Continue statement not inside a for loop.",
45+
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new ReplaceWithReturnQuickFix());
4546
}
4647
}
4748
};

testData/highlighting/continue.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import "fmt"
55
func _() {
66
for i := 0; i < 10; i++ {
77
fmt.Printf("%d\n", i)
8+
f := func() {
9+
<error>continue</error>
10+
}
11+
f()
812
continue
913
}
1014

@@ -13,4 +17,16 @@ func _() {
1317
if 1 > 0 {
1418
<error>continue</error>
1519
}
20+
21+
for i := 0; i < 10; i++ {
22+
defer func() {
23+
<error>continue</error>
24+
}()
25+
26+
go func() {
27+
<error>continue</error>
28+
}()
29+
30+
continue
31+
}
1632
}

0 commit comments

Comments
 (0)