Enable control flow checks for functions without body

Except checks for tail recursive calls

 #KT-7796 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2017-04-18 11:37:52 +03:00
parent a0d7b703f4
commit 7af10769c9
5 changed files with 36 additions and 3 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -879,6 +879,7 @@ class ControlFlowInformationProvider private constructor(
private fun markAndCheckRecursiveTailCalls(subroutineDescriptor: FunctionDescriptor) {
if (!subroutineDescriptor.isTailrec) return
if (subroutine is KtNamedFunction && !subroutine.hasBody()) return
// finally blocks are copied which leads to multiple diagnostics reported on one instruction
class KindAndCall(var kind: TailRecursionKind, internal val call: ResolvedCall<*>)
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -103,7 +103,6 @@ public class ControlFlowAnalyzer {
}
private void checkFunction(@NotNull BodiesResolveContext c, @NotNull KtDeclarationWithBody function, @Nullable KotlinType expectedReturnType) {
if (!function.hasBody()) return;
ControlFlowInformationProvider controlFlowInformationProvider =
new ControlFlowInformationProvider(function, trace, languageVersionSettings);
if (c.getTopDownAnalysisMode().isLocalDeclarations()) {
@@ -0,0 +1,9 @@
interface Inter {
fun foo(x: Int = <!UNINITIALIZED_PARAMETER!>y<!>, y: Int = x)
}
abstract class Abst {
abstract fun foo(x: Int = <!UNINITIALIZED_PARAMETER!>y<!>, y: Int = x)
}
<!NON_MEMBER_FUNCTION_NO_BODY!>fun extraDiagnostics(<!UNUSED_PARAMETER!>x<!>: Int = <!UNINITIALIZED_PARAMETER!>y<!>, <!UNUSED_PARAMETER!>y<!>: Int)<!>
@@ -0,0 +1,18 @@
package
public fun extraDiagnostics(/*0*/ x: kotlin.Int = ..., /*1*/ y: kotlin.Int): kotlin.Unit
public abstract class Abst {
public constructor Abst()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun foo(/*0*/ x: kotlin.Int = ..., /*1*/ y: kotlin.Int = ...): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface Inter {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun foo(/*0*/ x: kotlin.Int = ..., /*1*/ y: kotlin.Int = ...): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -188,6 +188,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("DefaultValuesCheckWithoutBody.kt")
public void testDefaultValuesCheckWithoutBody() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/DefaultValuesCheckWithoutBody.kt");
doTest(fileName);
}
@TestMetadata("DefaultValuesTypechecking.kt")
public void testDefaultValuesTypechecking() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/DefaultValuesTypechecking.kt");