Prohibit annotations, modifiers and default values for parameters in function type
#KT-7619 fixed
This commit is contained in:
@@ -24,13 +24,14 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors
|
import org.jetbrains.kotlin.diagnostics.Errors
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors.*
|
import org.jetbrains.kotlin.diagnostics.Errors.*
|
||||||
|
import org.jetbrains.kotlin.lexer.JetTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.codeFragmentUtil.debugTypeInfo
|
import org.jetbrains.kotlin.psi.codeFragmentUtil.debugTypeInfo
|
||||||
import org.jetbrains.kotlin.psi.debugText.getDebugText
|
import org.jetbrains.kotlin.psi.debugText.getDebugText
|
||||||
import org.jetbrains.kotlin.resolve.PossiblyBareType.type
|
import org.jetbrains.kotlin.resolve.PossiblyBareType.type
|
||||||
import org.jetbrains.kotlin.resolve.TypeResolver.FlexibleTypeCapabilitiesProvider
|
import org.jetbrains.kotlin.resolve.TypeResolver.FlexibleTypeCapabilitiesProvider
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.DynamicCallableDescriptors
|
|
||||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.recordScope
|
import org.jetbrains.kotlin.resolve.bindingContextUtil.recordScope
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.tasks.DynamicCallableDescriptors
|
||||||
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
|
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
|
||||||
import org.jetbrains.kotlin.resolve.lazy.LazyEntity
|
import org.jetbrains.kotlin.resolve.lazy.LazyEntity
|
||||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||||
@@ -239,6 +240,7 @@ public class TypeResolver(
|
|||||||
val receiverTypeRef = type.getReceiverTypeReference()
|
val receiverTypeRef = type.getReceiverTypeReference()
|
||||||
val receiverType = if (receiverTypeRef == null) null else resolveType(c.noBareTypes(), receiverTypeRef)
|
val receiverType = if (receiverTypeRef == null) null else resolveType(c.noBareTypes(), receiverTypeRef)
|
||||||
|
|
||||||
|
type.parameters.forEach { checkParameterInFunctionType(it) }
|
||||||
val parameterTypes = type.getParameters().map { resolveType(c.noBareTypes(), it.getTypeReference()!!) }
|
val parameterTypes = type.getParameters().map { resolveType(c.noBareTypes(), it.getTypeReference()!!) }
|
||||||
|
|
||||||
val returnTypeRef = type.getReturnTypeReference()
|
val returnTypeRef = type.getReturnTypeReference()
|
||||||
@@ -262,6 +264,31 @@ public class TypeResolver(
|
|||||||
override fun visitJetElement(element: JetElement) {
|
override fun visitJetElement(element: JetElement) {
|
||||||
c.trace.report(UNSUPPORTED.on(element, "Self-types are not supported yet"))
|
c.trace.report(UNSUPPORTED.on(element, "Self-types are not supported yet"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkParameterInFunctionType(param: JetParameter) {
|
||||||
|
if (param.hasDefaultValue()) {
|
||||||
|
c.trace.report(Errors.UNSUPPORTED.on(param.defaultValue!!, "default value of parameter in function type"))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param.nameIdentifier != null) {
|
||||||
|
for (annotationEntry in param.annotationEntries) {
|
||||||
|
c.trace.report(Errors.UNSUPPORTED.on(annotationEntry, "annotation on parameter in function type"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val modifierList = param.modifierList
|
||||||
|
if (modifierList != null) {
|
||||||
|
JetTokens.MODIFIER_KEYWORDS_ARRAY
|
||||||
|
.map { modifierList.getModifier(it) }
|
||||||
|
.filterNotNull()
|
||||||
|
.forEach { c.trace.report(Errors.UNSUPPORTED.on(it, "modifier on parameter in function type"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
param.valOrVarKeyword?.let {
|
||||||
|
c.trace.report(Errors.UNSUPPORTED.on(it, "val or val on parameter in function type"))
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return result ?: type(ErrorUtils.createErrorType(typeElement?.getDebugText() ?: "No type element"))
|
return result ?: type(ErrorUtils.createErrorType(typeElement?.getDebugText() ?: "No type element"))
|
||||||
|
|||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||||
|
|
||||||
|
fun f(x: Int = 0) {}
|
||||||
|
|
||||||
|
val inVal: (x: Int = <!UNSUPPORTED!>0<!>)->Unit = {}
|
||||||
|
|
||||||
|
fun inParam(fn: (x: Int = <!UNSUPPORTED!>0<!>)->Unit) {}
|
||||||
|
|
||||||
|
fun inParamNested(fn1: (fn2: (n: Int = <!UNSUPPORTED!>0<!>)->Unit)->Unit) {}
|
||||||
|
|
||||||
|
fun inReturn(): (x: Int = <!UNSUPPORTED!>0<!>)->Unit = {}
|
||||||
|
|
||||||
|
class A : (x: Int = <!UNSUPPORTED!>0<!>)->Unit {
|
||||||
|
override fun invoke(p1: Int) {
|
||||||
|
var lambda: (x: Int = <!UNSUPPORTED!>0<!>)->Unit = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
val prop: (x: Int = <!UNSUPPORTED!>0<!>)->Unit
|
||||||
|
get(): (x: Int = <!UNSUPPORTED!>0<!>)->Unit = {}
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public val inVal: (kotlin.Int) -> kotlin.Unit
|
||||||
|
public fun f(/*0*/ x: kotlin.Int = ...): kotlin.Unit
|
||||||
|
public fun inParam(/*0*/ fn: (kotlin.Int) -> kotlin.Unit): kotlin.Unit
|
||||||
|
public fun inParamNested(/*0*/ fn1: ((kotlin.Int) -> kotlin.Unit) -> kotlin.Unit): kotlin.Unit
|
||||||
|
public fun inReturn(): (kotlin.Int) -> kotlin.Unit
|
||||||
|
|
||||||
|
public final class A : (kotlin.Int) -> kotlin.Unit {
|
||||||
|
public constructor A()
|
||||||
|
public final val prop: (kotlin.Int) -> 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*/ fun invoke(/*0*/ p1: kotlin.Int): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||||
|
|
||||||
|
annotation class Ann
|
||||||
|
|
||||||
|
fun f(@Ann x: Int) {}
|
||||||
|
|
||||||
|
val inVal: (<!UNSUPPORTED!>@Ann<!> x: Int)->Unit = {}
|
||||||
|
|
||||||
|
fun inParam(fn: (<!UNSUPPORTED!>@Ann<!> x: Int)->Unit) {}
|
||||||
|
|
||||||
|
fun inParamNested(fn1: (fn2: (<!UNSUPPORTED!>@Ann<!> n: Int)->Unit)->Unit) {}
|
||||||
|
|
||||||
|
fun inReturn(): (<!UNSUPPORTED!>@Ann<!> x: Int)->Unit = {}
|
||||||
|
|
||||||
|
class A : (@<!DEBUG_INFO_MISSING_UNRESOLVED!>Ann<!> Int)->Unit {
|
||||||
|
override fun invoke(p1: Int) {
|
||||||
|
var lambda: (<!UNSUPPORTED!>@Ann<!> x: Int)->Unit = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
val prop: (<!UNSUPPORTED!>@Ann<!> x: Int)->Unit
|
||||||
|
get(): (<!UNSUPPORTED!>@Ann<!> x: Int)->Unit = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Target(AnnotationTarget.TYPE)
|
||||||
|
annotation class TypeAnn
|
||||||
|
|
||||||
|
val onType: (@TypeAnn A).(<!UNSUPPORTED!>@Ann<!> a: @TypeAnn A, @<!DEBUG_INFO_MISSING_UNRESOLVED!>TypeAnn<!> A)->@<!DEBUG_INFO_MISSING_UNRESOLVED!>TypeAnn<!> A? = <!EXPECTED_PARAMETERS_NUMBER_MISMATCH!>{<!> null }
|
||||||
|
|
||||||
|
fun (@TypeAnn A).extFun(@Ann a: @TypeAnn A): @<!DEBUG_INFO_MISSING_UNRESOLVED!>TypeAnn<!> A? = null
|
||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public val inVal: (kotlin.Int) -> kotlin.Unit
|
||||||
|
public val onType: @TypeAnn() A.(@TypeAnn() A, A) -> A?
|
||||||
|
public fun f(/*0*/ @Ann() x: kotlin.Int): kotlin.Unit
|
||||||
|
public fun inParam(/*0*/ fn: (kotlin.Int) -> kotlin.Unit): kotlin.Unit
|
||||||
|
public fun inParamNested(/*0*/ fn1: ((kotlin.Int) -> kotlin.Unit) -> kotlin.Unit): kotlin.Unit
|
||||||
|
public fun inReturn(): (kotlin.Int) -> kotlin.Unit
|
||||||
|
public fun @TypeAnn() A.extFun(/*0*/ @Ann() a: @TypeAnn() A): A?
|
||||||
|
|
||||||
|
public final class A : (kotlin.Int) -> kotlin.Unit {
|
||||||
|
public constructor A()
|
||||||
|
public final val prop: (kotlin.Int) -> 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*/ fun invoke(/*0*/ p1: kotlin.Int): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
@kotlin.annotation.annotation() public final class Ann : kotlin.Annotation {
|
||||||
|
public constructor Ann()
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) @kotlin.annotation.annotation() public final class TypeAnn : kotlin.Annotation {
|
||||||
|
public constructor TypeAnn()
|
||||||
|
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
|
||||||
|
}
|
||||||
Vendored
+1
-2
@@ -1,4 +1,3 @@
|
|||||||
package typeReferenceError
|
package typeReferenceError
|
||||||
|
|
||||||
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class Pair<!><<!SYNTAX!><!>:(val c: <!SYNTAX!><!SYNTAX!><!>fun<!><!SYNTAX!><!> <!UNRESOLVED_REFERENCE!>main<!>()
|
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class Pair<!><<!SYNTAX!><!>:(<!UNSUPPORTED!>val<!> c: <!SYNTAX!><!SYNTAX!><!>fun<!><!SYNTAX!><!> <!UNRESOLVED_REFERENCE!>main<!>()
|
||||||
|
|
||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||||
|
|
||||||
|
fun f(vararg x: Int) {}
|
||||||
|
|
||||||
|
val inVal: (<!UNSUPPORTED!>vararg<!> x: Int)->Unit = {}
|
||||||
|
|
||||||
|
fun inParam(fn: (<!UNSUPPORTED!>vararg<!> x: Int)->Unit) {}
|
||||||
|
|
||||||
|
fun inParamNested(fn1: (fn2: (<!UNSUPPORTED!>vararg<!> n: Int)->Unit)->Unit) {}
|
||||||
|
|
||||||
|
fun inReturn(): (<!UNSUPPORTED!>vararg<!> x: Int)->Unit = {}
|
||||||
|
|
||||||
|
class A : (<!UNSUPPORTED!>vararg<!> x: Int)->Unit {
|
||||||
|
override fun invoke(p1: Int) {
|
||||||
|
var lambda: (<!UNSUPPORTED!>vararg<!> x: Int)->Unit = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
val prop: (<!UNSUPPORTED!>vararg<!> x: Int)->Unit
|
||||||
|
get(): (<!UNSUPPORTED!>vararg<!> x: Int)->Unit = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
val allProhibited: (<!UNSUPPORTED!>abstract<!>
|
||||||
|
<!UNSUPPORTED!>annotation<!>
|
||||||
|
<!UNSUPPORTED!>companion<!>
|
||||||
|
<!UNSUPPORTED!>const<!>
|
||||||
|
<!UNSUPPORTED!>crossinline<!>
|
||||||
|
<!UNSUPPORTED!>data<!>
|
||||||
|
<!UNSUPPORTED!>enum<!>
|
||||||
|
<!UNSUPPORTED!>external<!>
|
||||||
|
<!UNSUPPORTED!>final<!>
|
||||||
|
<!UNSUPPORTED!>in<!>
|
||||||
|
<!UNSUPPORTED!>inline<!>
|
||||||
|
<!UNSUPPORTED!>inner<!>
|
||||||
|
<!UNSUPPORTED!>internal<!>
|
||||||
|
<!UNSUPPORTED!>lateinit<!>
|
||||||
|
<!UNSUPPORTED!>noinline<!>
|
||||||
|
<!UNSUPPORTED!>open<!>
|
||||||
|
<!UNSUPPORTED!>operator<!>
|
||||||
|
<!UNSUPPORTED!>out<!>
|
||||||
|
<!UNSUPPORTED!>override<!>
|
||||||
|
<!UNSUPPORTED!>private<!>
|
||||||
|
<!UNSUPPORTED!>protected<!>
|
||||||
|
<!UNSUPPORTED!>public<!>
|
||||||
|
<!UNSUPPORTED!>reified<!>
|
||||||
|
<!UNSUPPORTED!>sealed<!>
|
||||||
|
<!UNSUPPORTED!>tailrec<!>
|
||||||
|
<!UNSUPPORTED!>vararg<!>
|
||||||
|
|
||||||
|
x: Int)->Unit = {}
|
||||||
|
|
||||||
|
val valProhibited: (<!UNSUPPORTED!>val<!> x: Int)->Unit = {}
|
||||||
|
val varProhibited: (<!UNSUPPORTED!>var<!> x: Int)->Unit = {}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public val allProhibited: (kotlin.Int) -> kotlin.Unit
|
||||||
|
public val inVal: (kotlin.Int) -> kotlin.Unit
|
||||||
|
public val valProhibited: (kotlin.Int) -> kotlin.Unit
|
||||||
|
public val varProhibited: (kotlin.Int) -> kotlin.Unit
|
||||||
|
public fun f(/*0*/ vararg x: kotlin.Int /*kotlin.IntArray*/): kotlin.Unit
|
||||||
|
public fun inParam(/*0*/ fn: (kotlin.Int) -> kotlin.Unit): kotlin.Unit
|
||||||
|
public fun inParamNested(/*0*/ fn1: ((kotlin.Int) -> kotlin.Unit) -> kotlin.Unit): kotlin.Unit
|
||||||
|
public fun inReturn(): (kotlin.Int) -> kotlin.Unit
|
||||||
|
|
||||||
|
public final class A : (kotlin.Int) -> kotlin.Unit {
|
||||||
|
public constructor A()
|
||||||
|
public final val prop: (kotlin.Int) -> 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*/ fun invoke(/*0*/ p1: kotlin.Int): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
@@ -175,6 +175,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("DefaultValueForParameterInFunctionType.kt")
|
||||||
|
public void testDefaultValueForParameterInFunctionType() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/DefaultValueForParameterInFunctionType.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("DefaultValuesTypechecking.kt")
|
@TestMetadata("DefaultValuesTypechecking.kt")
|
||||||
public void testDefaultValuesTypechecking() throws Exception {
|
public void testDefaultValuesTypechecking() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/DefaultValuesTypechecking.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/DefaultValuesTypechecking.kt");
|
||||||
@@ -777,6 +783,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("annotationOnParameterInFunctionType.kt")
|
||||||
|
public void testAnnotationOnParameterInFunctionType() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/annotationOnParameterInFunctionType.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("AnnotationsForClasses.kt")
|
@TestMetadata("AnnotationsForClasses.kt")
|
||||||
public void testAnnotationsForClasses() throws Exception {
|
public void testAnnotationsForClasses() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/AnnotationsForClasses.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/AnnotationsForClasses.kt");
|
||||||
@@ -9411,6 +9423,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("modifierOnParameterInFunctionType.kt")
|
||||||
|
public void testModifierOnParameterInFunctionType() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/modifiers/modifierOnParameterInFunctionType.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("NoLocalVisibility.kt")
|
@TestMetadata("NoLocalVisibility.kt")
|
||||||
public void testNoLocalVisibility() throws Exception {
|
public void testNoLocalVisibility() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/modifiers/NoLocalVisibility.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/modifiers/NoLocalVisibility.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user