diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/UnreachableCode.kt b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/UnreachableCode.kt index b748efdf36a..b1597d88feb 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/UnreachableCode.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/UnreachableCode.kt @@ -26,6 +26,7 @@ import com.intellij.psi.PsiWhiteSpace import java.util.ArrayList import org.jetbrains.jet.lexer.JetTokens import com.intellij.psi.util.PsiTreeUtil +import com.intellij.psi.PsiComment trait UnreachableCode { val elements: Set @@ -70,7 +71,9 @@ class UnreachableCodeImpl( } fun List.removeReachableElementsWithMeaninglessSiblings(): List { - fun PsiElement.isMeaningless() = this is PsiWhiteSpace || this.getNode()?.getElementType() == JetTokens.COMMA + fun PsiElement.isMeaningless() = this is PsiWhiteSpace + || this.getNode()?.getElementType() == JetTokens.COMMA + || this is PsiComment val childrenToRemove = HashSet() fun collectSiblingsIfMeaningless(elementIndex: Int, direction: Int) { diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/commentsInDeadCode.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/commentsInDeadCode.kt new file mode 100644 index 00000000000..7640277569f --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/commentsInDeadCode.kt @@ -0,0 +1,22 @@ +package a + +fun test1() { + bar( + 11, + todo(),//comment1 + ""//comment2 + ) +} + +fun test2() { + bar(11, todo()/*comment1*/, ""/*comment2*/) +} +fun test3() { + bar(11, @l(todo()/*comment*/), "") +} + +fun todo() = throw Exception() + +fun bar(i: Int, s: String, a: Any) {} + + diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 80b66aba665..b37702a0811 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -1451,6 +1451,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/commasAndWhitespaces.kt"); } + @TestMetadata("commentsInDeadCode.kt") + public void testCommentsInDeadCode() throws Exception { + doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/commentsInDeadCode.kt"); + } + @TestMetadata("deadCallInInvokeCall.kt") public void testDeadCallInInvokeCall() throws Exception { doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCallInInvokeCall.kt");