提交 0e606a32 编写于 作者: A Alexey Tsvetkov

Prohibit named parameters in function types in supertype position

上级 90849a67
......@@ -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);
......
......@@ -10,7 +10,7 @@ fun inParamNested(fn1: (fn2: (n: Int = <!UNSUPPORTED!>0<!>)->Unit)->Unit) {}
fun inReturn(): (x: Int = <!UNSUPPORTED!>0<!>)->Unit = {}
class A : (x: Int = <!UNSUPPORTED!>0<!>)->Unit {
class A : (Int)->Unit {
override fun invoke(p1: Int) {
var lambda: (x: Int = <!UNSUPPORTED!>0<!>)->Unit = {}
}
......
abstract class A : Function1<Any, Unit>
abstract class B : (Int)->Unit
// Named parameter is prohibited because of possible inconsistency between
// type declaration and actual override
class C : (<!UNSUPPORTED!>x<!>: Int)->Unit {
override fun invoke(p1: Int): Unit {}
}
\ No newline at end of file
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
}
class A : (categoryName: <!SYNTAX!><!>)<!SYNTAX!><!> <!SYNTAX!><!>{<!SYNTAX!><!>
\ No newline at end of file
class A : (<!UNSUPPORTED!>categoryName<!>: <!SYNTAX!><!>)<!SYNTAX!><!> <!SYNTAX!><!>{<!SYNTAX!><!>
\ No newline at end of file
package typeReferenceError
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class Pair<!><<!SYNTAX!><!>:(<!UNSUPPORTED!>val<!> c: <!SYNTAX!><!SYNTAX!><!>fun<!><!SYNTAX!><!> <!UNRESOLVED_REFERENCE!>main<!>()
\ No newline at end of file
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class Pair<!><<!SYNTAX!><!>:(<!UNSUPPORTED!>val<!> <!UNSUPPORTED!>c<!>: <!SYNTAX!><!SYNTAX!><!>fun<!><!SYNTAX!><!> <!UNRESOLVED_REFERENCE!>main<!>()
\ No newline at end of file
......@@ -10,7 +10,7 @@ fun inParamNested(fn1: (fn2: (<!UNSUPPORTED!>vararg<!> n: Int)->Unit)->Unit) {}
fun inReturn(): (<!UNSUPPORTED!>vararg<!> x: Int)->Unit = {}
class A : (<!UNSUPPORTED!>vararg<!> x: Int)->Unit {
class A : (<!UNSUPPORTED!>vararg<!> Int)->Unit {
override fun invoke(p1: Int) {
var lambda: (<!UNSUPPORTED!>vararg<!> x: Int)->Unit = {}
}
......
......@@ -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");
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册