Added diagnostic error when in function declaration name was omitted
This commit is contained in:
@@ -333,6 +333,8 @@ public interface Errors {
|
||||
DiagnosticFactory1<JetFunction, SimpleFunctionDescriptor> NON_MEMBER_FUNCTION_NO_BODY =
|
||||
DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE);
|
||||
|
||||
DiagnosticFactory0<JetFunction> FUNCTION_DECLARATION_WITH_NO_NAME = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
|
||||
DiagnosticFactory0<JetParameter> VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<JetNamedFunction> NO_TAIL_CALLS_FOUND = DiagnosticFactory0.create(WARNING, DECLARATION_SIGNATURE);
|
||||
|
||||
@@ -32,7 +32,9 @@ public object PositioningStrategies {
|
||||
private open class DeclarationHeader<T : JetDeclaration> : PositioningStrategy<T>() {
|
||||
override fun isValid(element: T): Boolean {
|
||||
if (element is JetNamedDeclaration &&
|
||||
(element !is JetObjectDeclaration && element !is JetSecondaryConstructor)
|
||||
element !is JetObjectDeclaration &&
|
||||
element !is JetSecondaryConstructor &&
|
||||
element !is JetNamedFunction
|
||||
) {
|
||||
if (element.getNameIdentifier() == null) {
|
||||
return false
|
||||
@@ -103,6 +105,9 @@ public object PositioningStrategies {
|
||||
}
|
||||
return markElement(nameIdentifier)
|
||||
}
|
||||
if (element is JetNamedFunction) {
|
||||
return DECLARATION_SIGNATURE.mark(element)
|
||||
}
|
||||
return DEFAULT.mark(element)
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -224,6 +224,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(FINAL_FUNCTION_WITH_NO_BODY, "Function ''{0}'' without body cannot be final", NAME);
|
||||
|
||||
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(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");
|
||||
|
||||
@@ -237,7 +237,19 @@ public class DescriptorResolver {
|
||||
@NotNull DataFlowInfo dataFlowInfo
|
||||
) {
|
||||
return resolveFunctionDescriptor(containingDescriptor, scope, function, trace, dataFlowInfo,
|
||||
annotationResolver.resolveAnnotationsWithArguments(scope, function.getModifierList(), trace));
|
||||
annotationResolver.resolveAnnotationsWithArguments(scope, function.getModifierList(), trace), false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public SimpleFunctionDescriptor resolveAnonymousFunctionDescriptor(
|
||||
@NotNull DeclarationDescriptor containingDescriptor,
|
||||
@NotNull JetScope scope,
|
||||
@NotNull JetNamedFunction function,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull DataFlowInfo dataFlowInfo
|
||||
) {
|
||||
return resolveFunctionDescriptor(containingDescriptor, scope, function, trace, dataFlowInfo,
|
||||
annotationResolver.resolveAnnotationsWithArguments(scope, function.getModifierList(), trace), true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -249,7 +261,7 @@ public class DescriptorResolver {
|
||||
@NotNull DataFlowInfo dataFlowInfo
|
||||
) {
|
||||
return resolveFunctionDescriptor(containingDescriptor, scope, function, trace, dataFlowInfo,
|
||||
annotationResolver.resolveAnnotationsWithoutArguments(scope, function.getModifierList(), trace));
|
||||
annotationResolver.resolveAnnotationsWithoutArguments(scope, function.getModifierList(), trace), false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -259,12 +271,17 @@ public class DescriptorResolver {
|
||||
@NotNull final JetNamedFunction function,
|
||||
@NotNull final BindingTrace trace,
|
||||
@NotNull final DataFlowInfo dataFlowInfo,
|
||||
@NotNull Annotations annotations
|
||||
@NotNull Annotations annotations,
|
||||
boolean nameCanBeOmitted
|
||||
) {
|
||||
if (!nameCanBeOmitted && function.getName() == null) {
|
||||
trace.report(FUNCTION_DECLARATION_WITH_NO_NAME.on(function));
|
||||
}
|
||||
|
||||
final SimpleFunctionDescriptorImpl functionDescriptor = SimpleFunctionDescriptorImpl.create(
|
||||
containingDescriptor,
|
||||
annotations,
|
||||
JetPsiUtil.safeName(function.getName()),
|
||||
function.getNameAsSafeName(),
|
||||
CallableMemberDescriptor.Kind.DECLARATION,
|
||||
toSourceElement(function)
|
||||
);
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
annotation class a
|
||||
trait A
|
||||
trait B
|
||||
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME, CONFLICTING_OVERLOADS!>fun ()<!> {}
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME, CONFLICTING_OVERLOADS!>fun A.()<!> {}
|
||||
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME, CONFLICTING_OVERLOADS!>a fun ()<!> {}
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME, CONFLICTING_OVERLOADS!>fun [a] A.()<!> {}
|
||||
|
||||
class Outer {
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME, CONFLICTING_OVERLOADS!>fun ()<!> {}
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME!>fun B.()<!> {}
|
||||
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME, CONFLICTING_OVERLOADS!>a fun ()<!> {}
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME!>fun [a] A.()<!> {}
|
||||
}
|
||||
|
||||
fun outerFun() {
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME!>fun ()<!> {}
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME!>fun B.()<!> {}
|
||||
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME!>[a] fun ()<!> {}
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME!>fun [a] A.()<!> {}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package
|
||||
|
||||
a() internal fun <no name provided>(): kotlin.Unit
|
||||
internal fun <no name provided>(): kotlin.Unit
|
||||
internal fun outerFun(): kotlin.Unit
|
||||
internal fun A.<no name provided>(): kotlin.Unit
|
||||
internal fun A.<no name provided>(): kotlin.Unit
|
||||
|
||||
internal trait A {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
internal trait B {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
internal final class Outer {
|
||||
public constructor Outer()
|
||||
a() internal final fun <no name provided>(): kotlin.Unit
|
||||
internal final fun <no name provided>(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
internal final fun A.<no name provided>(): kotlin.Unit
|
||||
internal final fun B.<no name provided>(): kotlin.Unit
|
||||
}
|
||||
|
||||
internal final annotation class a : kotlin.Annotation {
|
||||
public constructor a()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
fun<!SYNTAX!><!> () {
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME!>fun ()<!> {
|
||||
|
||||
}
|
||||
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME!>fun Outer.()<!> {
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +29,7 @@ annotation class<!SYNTAX!><!> <!ANNOTATION_CLASS_WITH_BODY!>{
|
||||
}<!>
|
||||
|
||||
class Outer {
|
||||
fun<!SYNTAX!><!> () {
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME!>fun ()<!> {
|
||||
|
||||
}
|
||||
|
||||
@@ -50,4 +54,14 @@ class Outer {
|
||||
<!REDECLARATION!>annotation class<!SYNTAX!><!> <!ANNOTATION_CLASS_WITH_BODY!>{
|
||||
|
||||
}<!><!>
|
||||
}
|
||||
}
|
||||
|
||||
fun outerFun() {
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME!>fun ()<!> {
|
||||
|
||||
}
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME!>fun ()<!> {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package
|
||||
|
||||
internal val <no name provided>: kotlin.Int = 1
|
||||
internal fun <no name provided>(): kotlin.Unit
|
||||
internal fun outerFun(): kotlin.Unit
|
||||
internal fun Outer.<no name provided>(): kotlin.Unit
|
||||
|
||||
internal final class <no name provided> {
|
||||
internal constructor <no name provided>()
|
||||
|
||||
@@ -12,6 +12,6 @@ public class Nameless {
|
||||
import p.*
|
||||
|
||||
class K : <!INVISIBLE_MEMBER!>Nameless<!>() {
|
||||
fun<!SYNTAX!><!> () {}
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME!>fun ()<!> {}
|
||||
val<!SYNTAX!><!> : Int = 1
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
// !DIAGNOSTICS: -REDECLARATION
|
||||
|
||||
class C {
|
||||
fun<!SYNTAX!><!> () {
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME!>fun ()<!> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
package<!SYNTAX!><!>
|
||||
|
||||
fun<!SYNTAX!><!> () {
|
||||
<!FUNCTION_DECLARATION_WITH_NO_NAME!>fun ()<!> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2965,6 +2965,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("FunctionWithMissingNames.kt")
|
||||
public void testFunctionWithMissingNames() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/declarationChecks/FunctionWithMissingNames.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("illegalModifiersOnClass.kt")
|
||||
public void testIllegalModifiersOnClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/declarationChecks/illegalModifiersOnClass.kt");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class C {
|
||||
fun<error> </error>() {
|
||||
<error>fun ()</error> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package<EOLError></EOLError>
|
||||
|
||||
fun<error> </error>() {
|
||||
<error>fun ()</error> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// ERROR: Function declaration must have a name
|
||||
class Owner {
|
||||
fun <caret>() {}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// ERROR: Function declaration must have a name
|
||||
class Owner {
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// "class com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFixBase" "false"
|
||||
// ERROR: Unresolved reference: TTTTT
|
||||
// ERROR: Function declaration must have a name
|
||||
|
||||
fun () {
|
||||
val tttt : TTTTT = null
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// "Remove explicitly specified function return type" "true"
|
||||
// ERROR: Function declaration must have a name
|
||||
fun () {
|
||||
return<caret>
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
// "Remove explicitly specified function return type" "true"
|
||||
// ERROR: Function declaration must have a name
|
||||
fun (): Int {
|
||||
return<caret>
|
||||
}
|
||||
Reference in New Issue
Block a user