Implicit Nothing return type is now deprecated

This commit is contained in:
Mikhail Glukhikh
2015-10-09 17:42:36 +03:00
parent 65f0f312ff
commit 64543e3f52
27 changed files with 47 additions and 21 deletions
@@ -694,6 +694,8 @@ public interface Errors {
DiagnosticFactory2<JetElement, JetType, JetType> INCOMPATIBLE_TYPES = DiagnosticFactory2.create(ERROR);
DiagnosticFactory0<PsiElement> IMPLICIT_NOTHING_RETURN_TYPE = DiagnosticFactory0.create(WARNING);
// Context tracking
DiagnosticFactory1<JetExpression, JetExpression> EXPRESSION_EXPECTED = DiagnosticFactory1.create(ERROR);
@@ -525,6 +525,7 @@ public class DefaultErrorMessages {
RENDER_TYPE);
MAP.put(TYPE_MISMATCH_IN_CONDITION, "Condition must be of type kotlin.Boolean, but is of type {0}", RENDER_TYPE);
MAP.put(INCOMPATIBLE_TYPES, "Incompatible types: {0} and {1}", RENDER_TYPE, RENDER_TYPE);
MAP.put(IMPLICIT_NOTHING_RETURN_TYPE, "''Nothing'' return type needs to be specified explicitly");
MAP.put(EXPECTED_CONDITION, "Expected condition of type kotlin.Boolean");
MAP.put(CANNOT_CHECK_FOR_ERASED, "Cannot check for instance of erased type: {0}", RENDER_TYPE);
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.lexer.JetTokens;
import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.types.*;
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
import java.util.*;
@@ -641,6 +642,9 @@ public class DeclarationsChecker {
if (!function.hasBody() && !hasAbstractModifier) {
trace.report(NON_MEMBER_FUNCTION_NO_BODY.on(function, functionDescriptor));
}
if (TypeUtilsKt.isNothing(functionDescriptor.getReturnType()) && !function.hasDeclaredReturnType()) {
trace.report(IMPLICIT_NOTHING_RETURN_TYPE.on(function.getNameIdentifier() != null ? function.getNameIdentifier() : function));
}
checkFunctionExposedType(function, functionDescriptor);
}
@@ -1,6 +1,6 @@
fun a(): IntArray? = null
fun b() = throw Exception()
fun b(): Nothing = throw Exception()
fun foo(): IntArray = a() ?: b()
@@ -1,6 +1,6 @@
fun a(): String? = null
fun b() = throw Exception()
fun b(): Nothing = throw Exception()
fun foo(): String = a() ?: b()
@@ -6,7 +6,7 @@ fun testCommasAndWhitespaces() {
<!UNREACHABLE_CODE!>bar(<!> 1 , todo() , <!UNREACHABLE_CODE!>"" )<!>
}
fun todo() = throw Exception()
fun todo(): Nothing = throw Exception()
@@ -15,7 +15,7 @@ fun test3() {
<!UNREACHABLE_CODE!>bar(<!>11, l@(todo()/*comment*/), <!UNREACHABLE_CODE!>"")<!>
}
fun todo() = throw Exception()
fun todo(): Nothing = throw Exception()
fun bar(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>s<!>: String, <!UNUSED_PARAMETER!>a<!>: Any) {}
@@ -8,4 +8,4 @@ fun testInvokeWithLambda() {
todo()<!UNREACHABLE_CODE!>(1){ 42 }<!>
}
fun todo() = throw Exception()
fun todo(): Nothing = throw Exception()
@@ -8,4 +8,4 @@ fun test12() {
todo()<!UNNECESSARY_SAFE_CALL!>?.<!><!UNREACHABLE_CODE!>bar(1)<!>
}
fun todo() = throw Exception()
fun todo(): Nothing = throw Exception()
@@ -14,7 +14,7 @@ fun test3() {
<!UNREACHABLE_CODE!>bar()<!>
}
fun throwNPE() = null!!
fun throwNPE(): Nothing = null!!
class A {
operator fun plus(<!UNUSED_PARAMETER!>a<!>: A): Nothing = throw Exception()
@@ -37,4 +37,4 @@ fun testArrayPlusAssign(array: Array<Any>) {
array[1] <!UNREACHABLE_CODE!>+=<!> todo()
}
fun todo() = throw Exception()
fun todo(): Nothing = throw Exception()
@@ -15,4 +15,4 @@ fun testPlusAssign() {
}
fun todo() = throw Exception()
fun todo(): Nothing = throw Exception()
@@ -35,5 +35,5 @@ fun returnInBinary2(): Boolean {
(return true) <!UNREACHABLE_CODE!>|| (return false)<!>
}
fun todo() = throw Exception()
fun todo(): Nothing = throw Exception()
fun bar() {}
@@ -10,4 +10,4 @@ fun testArgumentInVariableAsFunctionCall(f: (Any) -> Unit) {
f<!UNREACHABLE_CODE!>(<!>todo()<!UNREACHABLE_CODE!>)<!>
}
fun todo() = throw Exception()
fun todo(): Nothing = throw Exception()
@@ -21,4 +21,4 @@ fun unreachable4(array: Array<Any>) {
}
fun bar(a: Any) {}
fun todo() = throw Exception()
fun todo(): Nothing = throw Exception()
@@ -8,5 +8,5 @@ fun testIf1(b: Boolean) {
bar()
}
fun todo() = throw Exception()
fun todo(): Nothing = throw Exception()
fun bar() {}
@@ -10,4 +10,4 @@ fun testCompound1() {
<!UNREACHABLE_CODE!>(<!>todo() <!UNREACHABLE_CODE!>* "")[1]<!>
}
fun todo() = throw Exception()
fun todo(): Nothing = throw Exception()
@@ -32,5 +32,5 @@ fun testFunctionDefaultArgument() {
open class Foo(i: Int) {}
fun todo() = throw Exception()
fun todo(): Nothing = throw Exception()
fun bar() {}
@@ -17,5 +17,5 @@ fun testDoWhile() {
<!UNREACHABLE_CODE!>bar()<!>
}
fun todo() = throw Exception()
fun todo(): Nothing = throw Exception()
fun bar() {}
@@ -2,4 +2,4 @@ fun testReturn() {
<!UNREACHABLE_CODE!>return<!> todo()
}
fun todo() = throw Exception()
fun todo(): Nothing = throw Exception()
@@ -12,4 +12,4 @@ fun testPostfixSpecial() {
todo()<!UNNECESSARY_NOT_NULL_ASSERTION, UNREACHABLE_CODE!>!!<!>
}
fun todo() = throw Exception()
fun todo(): Nothing = throw Exception()
@@ -0,0 +1,7 @@
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>foo<!>() = throw Exception()
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>bar<!>() = null!!
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>baz<!>() = bar()
fun gav(): Any = null!!
@@ -0,0 +1,6 @@
package
public fun bar(): kotlin.Nothing
public fun baz(): kotlin.Nothing
public fun foo(): kotlin.Nothing
public fun gav(): kotlin.Any
+1 -1
View File
@@ -45,4 +45,4 @@ fun test4() {
}
}
fun fail() = throw Exception()
fun fail(): Nothing = throw Exception()
@@ -19,4 +19,4 @@ fun foo1(e: PsiElement) {
}
//from library
fun println(any: Any?) = throw Exception("$any")
fun println(any: Any?): Nothing = throw Exception("$any")
@@ -265,6 +265,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("implicitNothing.kt")
public void testImplicitNothing() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/implicitNothing.kt");
doTest(fileName);
}
@TestMetadata("IncDec.kt")
public void testIncDec() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/IncDec.kt");
+1 -1
View File
@@ -2,7 +2,7 @@ package kotlin
// This file should be excluded from tests using StdLib, as these methods conflict with corresponding methods from kotlin.test
// see StdLibTestBase.removeAdHocAssertions
fun fail(message: String? = null) = throw Exception(message)
fun fail(message: String? = null): Nothing = throw Exception(message)
fun assertEquals<T>(expected: T, actual: T, message: String? = null) {
if (expected != actual) {