diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java index 3213dd3dc7a..2b0b9894d64 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java @@ -427,6 +427,17 @@ public class BodyResolver { JetTypeReference typeReference = entry.getKey(); JetType supertype = entry.getValue(); + JetTypeElement typeElement = typeReference.getTypeElement(); + if (typeElement instanceof JetFunctionType) { + for (JetParameter parameter : ((JetFunctionType) typeElement).getParameters()) { + PsiElement nameIdentifier = parameter.getNameIdentifier(); + + if (nameIdentifier != null) { + trace.report(Errors.UNSUPPORTED.on(nameIdentifier, "named parameter in function type in supertype position")); + } + } + } + boolean addSupertype = true; ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(supertype); diff --git a/compiler/testData/diagnostics/tests/DefaultValueForParameterInFunctionType.kt b/compiler/testData/diagnostics/tests/DefaultValueForParameterInFunctionType.kt index f9b0f6f68ac..a90120e3c81 100644 --- a/compiler/testData/diagnostics/tests/DefaultValueForParameterInFunctionType.kt +++ b/compiler/testData/diagnostics/tests/DefaultValueForParameterInFunctionType.kt @@ -10,7 +10,7 @@ fun inParamNested(fn1: (fn2: (n: Int = 0)->Unit)->Unit) {} fun inReturn(): (x: Int = 0)->Unit = {} -class A : (x: Int = 0)->Unit { +class A : (Int)->Unit { override fun invoke(p1: Int) { var lambda: (x: Int = 0)->Unit = {} } diff --git a/compiler/testData/diagnostics/tests/NamedFunctionTypeParameterInSupertype.kt b/compiler/testData/diagnostics/tests/NamedFunctionTypeParameterInSupertype.kt new file mode 100644 index 00000000000..c9567ff0765 --- /dev/null +++ b/compiler/testData/diagnostics/tests/NamedFunctionTypeParameterInSupertype.kt @@ -0,0 +1,9 @@ +abstract class A : Function1 + +abstract class B : (Int)->Unit + +// Named parameter is prohibited because of possible inconsistency between +// type declaration and actual override +class C : (x: Int)->Unit { + override fun invoke(p1: Int): Unit {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/NamedFunctionTypeParameterInSupertype.txt b/compiler/testData/diagnostics/tests/NamedFunctionTypeParameterInSupertype.txt new file mode 100644 index 00000000000..c53915ae9aa --- /dev/null +++ b/compiler/testData/diagnostics/tests/NamedFunctionTypeParameterInSupertype.txt @@ -0,0 +1,25 @@ +package + +public abstract class A : (kotlin.Any) -> kotlin.Unit { + 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 abstract override /*1*/ /*fake_override*/ fun invoke(/*0*/ p1: kotlin.Any): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class B : (kotlin.Int) -> kotlin.Unit { + public constructor 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 abstract override /*1*/ /*fake_override*/ fun invoke(/*0*/ p1: kotlin.Int): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class C : (kotlin.Int) -> kotlin.Unit { + public constructor C() + 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*/ fun invoke(/*0*/ p1: kotlin.Int): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funcitonTypes.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funcitonTypes.kt index 36c7d2ced15..09f9ebd4fff 100644 --- a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funcitonTypes.kt +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funcitonTypes.kt @@ -1 +1 @@ -class A : (categoryName: ) { \ No newline at end of file +class A : (categoryName: ) { \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/typeReferenceError.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/typeReferenceError.kt index d01e25e24dc..5fc835b5310 100644 --- a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/typeReferenceError.kt +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/typeReferenceError.kt @@ -1,3 +1,3 @@ package typeReferenceError -class Pair<:(val c: fun main() \ No newline at end of file +class Pair<:(val c: fun main() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/modifiers/modifierOnParameterInFunctionType.kt b/compiler/testData/diagnostics/tests/modifiers/modifierOnParameterInFunctionType.kt index 10a3ad8302f..d70d5650adf 100644 --- a/compiler/testData/diagnostics/tests/modifiers/modifierOnParameterInFunctionType.kt +++ b/compiler/testData/diagnostics/tests/modifiers/modifierOnParameterInFunctionType.kt @@ -10,7 +10,7 @@ fun inParamNested(fn1: (fn2: (vararg n: Int)->Unit)->Unit) {} fun inReturn(): (vararg x: Int)->Unit = {} -class A : (vararg x: Int)->Unit { +class A : (vararg Int)->Unit { override fun invoke(p1: Int) { var lambda: (vararg x: Int)->Unit = {} } diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index fd9dd0ef3d5..4f465311dde 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -379,6 +379,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("NamedFunctionTypeParameterInSupertype.kt") + public void testNamedFunctionTypeParameterInSupertype() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/NamedFunctionTypeParameterInSupertype.kt"); + doTest(fileName); + } + @TestMetadata("Nullability.kt") public void testNullability() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/Nullability.kt"); diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveTopLevelDeclarations/MoveKotlinTopLevelDeclarationsProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveTopLevelDeclarations/MoveKotlinTopLevelDeclarationsProcessor.kt index 0e32fc802f7..63a8517ca9d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveTopLevelDeclarations/MoveKotlinTopLevelDeclarationsProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveTopLevelDeclarations/MoveKotlinTopLevelDeclarationsProcessor.kt @@ -61,11 +61,9 @@ import org.jetbrains.kotlin.psi.psiUtil.isInsideOf import org.jetbrains.kotlin.psi.psiUtil.isPrivate import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.utils.keysToMap -import java.util.ArrayList -import java.util.HashMap -import java.util.HashSet +import java.util.* -interface Mover: (originalElement: JetNamedDeclaration, targetFile: JetFile) -> JetNamedDeclaration { +interface Mover: (JetNamedDeclaration, JetFile) -> JetNamedDeclaration { object Default: Mover { override fun invoke(originalElement: JetNamedDeclaration, targetFile: JetFile): JetNamedDeclaration { val newElement = targetFile.add(originalElement) as JetNamedDeclaration