Deprecate function expressions with names

This commit is contained in:
Denis Zharkov
2015-05-16 19:04:36 +03:00
parent aa1548a83b
commit 2deb7faf05
20 changed files with 49 additions and 41 deletions
@@ -350,6 +350,7 @@ public interface Errors {
DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE);
DiagnosticFactory0<JetFunction> FUNCTION_DECLARATION_WITH_NO_NAME = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
DiagnosticFactory0<PsiElement> FUNCTION_EXPRESSION_WITH_NAME = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<JetParameter> VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION = DiagnosticFactory0.create(ERROR);
@@ -197,6 +197,7 @@ public class DefaultErrorMessages {
MAP.put(NON_MEMBER_FUNCTION_NO_BODY, "Function ''{0}'' must have a body", NAME);
MAP.put(FUNCTION_DECLARATION_WITH_NO_NAME, "Function declaration must have a name");
MAP.put(FUNCTION_EXPRESSION_WITH_NAME, "Function expressions with names are deprecated");
MAP.put(NON_FINAL_MEMBER_IN_FINAL_CLASS, "\"open\" has no effect in a final class");
MAP.put(PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE, "Public or protected member should have specified type");
@@ -59,6 +59,11 @@ public class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Express
if (!function.getTypeParameters().isEmpty()) {
context.trace.report(TYPE_PARAMETERS_NOT_ALLOWED.on(function))
}
if (function.getName() != null) {
context.trace.report(FUNCTION_EXPRESSION_WITH_NAME.on(function.getNameIdentifier()))
}
for (parameter in function.getValueParameters()) {
if (parameter.hasDefaultValue()) {
context.trace.report(FUNCTION_EXPRESSION_PARAMETER_WITH_DEFAULT_VALUE.on(parameter))
@@ -5,7 +5,7 @@ fun test(<!VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION!>a<!>) {
class A(a<!SYNTAX!><!>)
val bar = fun test(<!CANNOT_INFER_PARAMETER_TYPE!>a<!>){}
val bar = fun(<!CANNOT_INFER_PARAMETER_TYPE!>a<!>){}
val la = { <!CANNOT_INFER_PARAMETER_TYPE!>a<!> -> }
val las = { a: Int -> }
@@ -4,6 +4,6 @@ fun test(@ann <!UNUSED_PARAMETER!>p<!>: Int) {
}
val bar = fun test(@ann <!UNUSED_PARAMETER!>g<!>: Int) {}
val bar = fun(@ann <!UNUSED_PARAMETER!>g<!>: Int) {}
val bas = { <!DEPRECATED_LAMBDA_SYNTAX!>(@ann t: Int)<!> -> }
@@ -6,10 +6,6 @@ fun autolabel(l: List<Int>) = l.map (fun (i: Int): Int {
return@map 4
})
fun unresolvedMapLabel(l: List<Int>) = l.map (fun test(i: Int): Int {
fun unresolvedMapLabel(l: List<Int>) = l.map (l@ fun(i: Int): Int {
return<!UNRESOLVED_REFERENCE!>@map<!> 4
})
fun labelToFunName(l: List<Int>) = l.map (fun test(i: Int): Int {
return@test 4
})
@@ -1,6 +1,5 @@
package
internal fun autolabel(/*0*/ l: kotlin.List<kotlin.Int>): kotlin.List<kotlin.Int>
internal fun labelToFunName(/*0*/ l: kotlin.List<kotlin.Int>): kotlin.List<kotlin.Int>
internal fun unresolvedMapLabel(/*0*/ l: kotlin.List<kotlin.Int>): kotlin.List<kotlin.Int>
internal fun </*0*/ T, /*1*/ R> kotlin.Iterable<T>.map(/*0*/ transform: (T) -> R): kotlin.List<R>
@@ -6,8 +6,6 @@ val ok = "OK"
class A
val withName = fun name() {}
val extensionWithName = fun A.name() {}
val withoutName = fun () {}
val extensionWithoutName = fun A.() {}
@@ -1,13 +1,11 @@
package
internal val extensionWithName: A.() -> kotlin.Unit
internal val extensionWithoutName: A.() -> kotlin.Unit
internal val funfun: () -> () -> kotlin.Int
internal val ok: kotlin.String = "OK"
internal val parentesized: () -> kotlin.Unit
internal val parentesizedWithType: () -> kotlin.Unit
internal val withExpression: () -> kotlin.Int
internal val withName: () -> kotlin.Unit
internal val withReturn: () -> kotlin.Int
internal val withType: () -> kotlin.Unit
internal val withoutName: () -> kotlin.Unit
@@ -3,5 +3,5 @@
fun <T> foo(f : (T) -> T) : T = throw Exception()
fun test() {
val a : Int = foo(fun f(x) = x)
val a : Int = foo(fun (x) = x)
}
@@ -19,9 +19,4 @@ fun foo() {
}
return@bag
}
val bag = fun name() {
val bar = fun () {
<!RETURN_NOT_ALLOWED!>return@name<!>
}
}
}
@@ -0,0 +1,11 @@
fun foo() {
fun run(block: () -> Unit) = block()
class A
fun bar() {}
(fun <!FUNCTION_EXPRESSION_WITH_NAME!>bar<!>() {})
fun A.foo() {}
(fun A.<!FUNCTION_EXPRESSION_WITH_NAME!>foo<!>() {})
run(fun <!FUNCTION_EXPRESSION_WITH_NAME!>foo<!>() {})
}
@@ -0,0 +1,3 @@
package
internal fun foo(): kotlin.Unit
@@ -1,18 +1,18 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
val bar = fun name() {}
val bas = fun name() {}
val bar = fun() {}
val bas = fun() {}
fun gar(p: Any?) = fun name() {}
fun gas(p: Any?) = fun name() {}
fun gar(p: Any?) = fun() {}
fun gas(p: Any?) = fun() {}
fun outer() {
val bar = fun name() {}
val bas = fun name() {}
val bar = fun() {}
val bas = fun() {}
fun gar(p: Any?) = fun name() {}
fun gas(p: Any?) = fun name() {}
fun gar(p: Any?) = fun() {}
fun gas(p: Any?) = fun() {}
gar(fun name() {})
gar(fun name() {})
gar(fun() {})
gar(fun() {})
}
@@ -7,7 +7,3 @@ val label_fun = label@ fun () {
val parenthesized_label_fun = (label@ fun () {
return@label
})
val fun_with_name = fun name() {
return@name
}
@@ -1,5 +1,4 @@
package
internal val fun_with_name: () -> kotlin.Unit
internal val label_fun: () -> kotlin.Unit
internal val parenthesized_label_fun: () -> kotlin.Unit
@@ -11,8 +11,8 @@ fun fun_with_where() = fun <!TYPE_PARAMETERS_NOT_ALLOWED!><T><!> T.(t: T): T whe
fun outer() {
devNull(fun <!TYPE_PARAMETERS_NOT_ALLOWED!><T><!>() {})
devNull(fun <!TYPE_PARAMETERS_NOT_ALLOWED!><T><!> T.name() {})
devNull(fun <!TYPE_PARAMETERS_NOT_ALLOWED!><T><!> name(): T = null!!)
devNull(fun <!TYPE_PARAMETERS_NOT_ALLOWED!><T><!> name(t: T) {})
devNull(fun <!TYPE_PARAMETERS_NOT_ALLOWED!><T><!> name() where T:A {})
devNull(fun <!TYPE_PARAMETERS_NOT_ALLOWED!><T><!> T.() {})
devNull(fun <!TYPE_PARAMETERS_NOT_ALLOWED!><T><!> (): T = null!!)
devNull(fun <!TYPE_PARAMETERS_NOT_ALLOWED!><T><!> (t: T) {})
devNull(fun <!TYPE_PARAMETERS_NOT_ALLOWED!><T><!> () where T:A {})
}
@@ -3,10 +3,10 @@
annotation class ann
val bas = <!NON_MEMBER_FUNCTION_NO_BODY!>fun ()<!>
fun bar(a: Any) = <!NON_MEMBER_FUNCTION_NO_BODY!>fun name()<!>
fun bar(a: Any) = <!NON_MEMBER_FUNCTION_NO_BODY!>fun ()<!>
fun outer() {
bar(<!NON_MEMBER_FUNCTION_NO_BODY!>fun ()<!>)
bar(<!NON_MEMBER_FUNCTION_NO_BODY!>fun name()<!>)
bar(<!NON_MEMBER_FUNCTION_NO_BODY!>@ann fun name()<!>)
bar(l@ <!NON_MEMBER_FUNCTION_NO_BODY!>fun ()<!>)
bar(<!NON_MEMBER_FUNCTION_NO_BODY!>@ann fun ()<!>)
}
@@ -1,6 +1,6 @@
fun test1() {
<!TYPE_MISMATCH!>1<!>. (fun String.(i: Int) = i )(1)
<!TYPE_MISMATCH!>1<!>.(fun String.label(i: Int) = i )(1)
<!TYPE_MISMATCH!>1<!>.(label@ fun String.(i: Int) = i )(1)
}
fun test2(f: String.(Int) -> Unit) {
@@ -4785,6 +4785,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("NameDeprecation.kt")
public void testNameDeprecation() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionAsExpression/NameDeprecation.kt");
doTest(fileName);
}
@TestMetadata("NoOverloadError.kt")
public void testNoOverloadError() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionAsExpression/NoOverloadError.kt");