FIR: report NO_TYPE_ARGUMENTS_ON_RHS properly
This commit is contained in:
+4
@@ -250,6 +250,10 @@ object DIAGNOSTICS_LIST : DiagnosticList() {
|
||||
parameter<Int>("expectedCount")
|
||||
parameter<FirClassLikeSymbol<*>>("classifier")
|
||||
}
|
||||
val NO_TYPE_ARGUMENTS_ON_RHS by error<FirSourceElement, PsiElement> {
|
||||
parameter<Int>("expectedCount")
|
||||
parameter<FirClassLikeSymbol<*>>("classifier")
|
||||
}
|
||||
val TYPE_PARAMETERS_IN_OBJECT by error<FirSourceElement, PsiElement>()
|
||||
val ILLEGAL_PROJECTION_USAGE by error<FirSourceElement, PsiElement>()
|
||||
val TYPE_PARAMETERS_IN_ENUM by error<FirSourceElement, PsiElement>()
|
||||
|
||||
@@ -192,6 +192,7 @@ object FirErrors {
|
||||
val UPPER_BOUND_VIOLATED by error2<FirSourceElement, PsiElement, FirTypeParameterSymbol, ConeKotlinType>()
|
||||
val TYPE_ARGUMENTS_NOT_ALLOWED by error0<FirSourceElement, PsiElement>()
|
||||
val WRONG_NUMBER_OF_TYPE_ARGUMENTS by error2<FirSourceElement, PsiElement, Int, FirClassLikeSymbol<*>>()
|
||||
val NO_TYPE_ARGUMENTS_ON_RHS by error2<FirSourceElement, PsiElement, Int, FirClassLikeSymbol<*>>()
|
||||
val TYPE_PARAMETERS_IN_OBJECT by error0<FirSourceElement, PsiElement>()
|
||||
val ILLEGAL_PROJECTION_USAGE by error0<FirSourceElement, PsiElement>()
|
||||
val TYPE_PARAMETERS_IN_ENUM by error0<FirSourceElement, PsiElement>()
|
||||
|
||||
+2
@@ -44,6 +44,8 @@ private fun ConeDiagnostic.toFirDiagnostic(
|
||||
is ConeIllegalAnnotationError -> FirErrors.NOT_AN_ANNOTATION_CLASS.on(source, this.name.asString())
|
||||
is ConeWrongNumberOfTypeArgumentsError ->
|
||||
FirErrors.WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(qualifiedAccessSource ?: source, this.desiredCount, this.type)
|
||||
is ConeNoTypeArgumentsOnRhsError ->
|
||||
FirErrors.NO_TYPE_ARGUMENTS_ON_RHS.on(qualifiedAccessSource ?: source, this.desiredCount, this.type)
|
||||
is ConeSimpleDiagnostic -> when {
|
||||
source.kind is FirFakeSourceElementKind -> null
|
||||
else -> this.getFactory().on(qualifiedAccessSource ?: source)
|
||||
|
||||
+13
-1
@@ -70,10 +70,22 @@ class ConeIllegalAnnotationError(val name: Name) : ConeDiagnostic() {
|
||||
override val reason: String get() = "Not a legal annotation: $name"
|
||||
}
|
||||
|
||||
class ConeWrongNumberOfTypeArgumentsError(val desiredCount: Int, val type: FirClassLikeSymbol<*>) : ConeDiagnostic() {
|
||||
abstract class ConeUnmatchedTypeArgumentsError(val desiredCount: Int, val type: FirClassLikeSymbol<*>) : ConeDiagnostic()
|
||||
|
||||
class ConeWrongNumberOfTypeArgumentsError(
|
||||
desiredCount: Int,
|
||||
type: FirClassLikeSymbol<*>
|
||||
) : ConeUnmatchedTypeArgumentsError(desiredCount, type) {
|
||||
override val reason: String get() = "Wrong number of type arguments"
|
||||
}
|
||||
|
||||
class ConeNoTypeArgumentsOnRhsError(
|
||||
desiredCount: Int,
|
||||
type: FirClassLikeSymbol<*>
|
||||
) : ConeUnmatchedTypeArgumentsError(desiredCount, type) {
|
||||
override val reason: String get() = "No type arguments on RHS"
|
||||
}
|
||||
|
||||
class ConeInstanceAccessBeforeSuperCall(val target: String) : ConeDiagnostic() {
|
||||
override val reason: String get() = "Cannot access ''${target}'' before superclass constructor has been called"
|
||||
}
|
||||
|
||||
+1
-1
@@ -502,7 +502,7 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
|
||||
val originalType = argument.typeRef.coneTypeSafe<ConeKotlinType>() ?: return this
|
||||
val newType = computeRepresentativeTypeForBareType(type, originalType) ?: return buildErrorTypeRef {
|
||||
source = this@withTypeArgumentsForBareType.source
|
||||
diagnostic = ConeWrongNumberOfTypeArgumentsError(firClass.typeParameters.size, firClass.symbol)
|
||||
diagnostic = ConeNoTypeArgumentsOnRhsError(firClass.typeParameters.size, firClass.symbol)
|
||||
}
|
||||
return if (newType.typeArguments.isEmpty()) this else withReplacedConeType(newType)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ interface Tr
|
||||
interface G<T>
|
||||
|
||||
fun test(tr: Tr) {
|
||||
val v = tr as <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>G?<!>
|
||||
val v = tr as <!NO_TYPE_ARGUMENTS_ON_RHS!>G?<!>
|
||||
// If v is not nullable, there will be a warning on this line:
|
||||
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><G<*>>(v!!)
|
||||
}
|
||||
@@ -4,6 +4,6 @@ interface Tr
|
||||
interface G<T>
|
||||
|
||||
fun test(tr: Tr?) {
|
||||
val v = tr as <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>G<!>
|
||||
val v = tr as <!NO_TYPE_ARGUMENTS_ON_RHS!>G<!>
|
||||
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><G<*>>(v)
|
||||
}
|
||||
+1
-1
@@ -4,6 +4,6 @@ interface Tr
|
||||
interface G<T>
|
||||
|
||||
fun test(tr: Tr?) {
|
||||
val v = tr as <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>G?<!>
|
||||
val v = tr as <!NO_TYPE_ARGUMENTS_ON_RHS!>G?<!>
|
||||
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><G<*>>(v!!)
|
||||
}
|
||||
@@ -4,6 +4,6 @@ interface Tr
|
||||
interface G<T>
|
||||
|
||||
fun test(tr: Tr) {
|
||||
val v = tr as <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>G<!>
|
||||
val v = tr as <!NO_TYPE_ARGUMENTS_ON_RHS!>G<!>
|
||||
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><G<*>>(v)
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
interface Tr
|
||||
interface G<T>
|
||||
|
||||
fun test(tr: Tr) = tr is <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>G<!>
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
interface Tr
|
||||
interface G<T>
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@ package p
|
||||
|
||||
public fun foo(a: Any) {
|
||||
a is <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Map<Int><!>
|
||||
a is <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Map<!>
|
||||
a is <!NO_TYPE_ARGUMENTS_ON_RHS!>Map<!>
|
||||
a is Map<out Any?, Any?>
|
||||
a is Map<*, *>
|
||||
a is Map<<!SYNTAX!><!>>
|
||||
a is List<Map>
|
||||
a is <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>List<!>
|
||||
a is <!NO_TYPE_ARGUMENTS_ON_RHS!>List<!>
|
||||
a is Int
|
||||
|
||||
(a as <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Map<!>) is Int
|
||||
(a as <!NO_TYPE_ARGUMENTS_ON_RHS!>Map<!>) is Int
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
public fun foo(a: Any, b: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Map<!>) {
|
||||
when (a) {
|
||||
is <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Map<Int><!> -> {}
|
||||
is <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Map<!> -> {}
|
||||
is <!NO_TYPE_ARGUMENTS_ON_RHS!>Map<!> -> {}
|
||||
is Map<out Any?, Any?> -> {}
|
||||
is Map<*, *> -> {}
|
||||
is Map<<!SYNTAX!><!>> -> {}
|
||||
is List<Map> -> {}
|
||||
is <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>List<!> -> {}
|
||||
is <!NO_TYPE_ARGUMENTS_ON_RHS!>List<!> -> {}
|
||||
is Int -> {}
|
||||
else -> {}
|
||||
}
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ class DerivedOuter<G> : SuperOuter<G>() {
|
||||
|
||||
fun bare(x: SuperOuter<*>.SuperInner<*>, y: Any?) {
|
||||
if (x is SuperOuter.SuperInner) return
|
||||
if (y is <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>SuperOuter.SuperInner<!>) {
|
||||
if (y is <!NO_TYPE_ARGUMENTS_ON_RHS!>SuperOuter.SuperInner<!>) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -12,7 +12,7 @@ class Outer<E> {
|
||||
x.prop.checkType { _<E>() }
|
||||
}
|
||||
|
||||
if (y is <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Inner<!>) return
|
||||
if (y is <!NO_TYPE_ARGUMENTS_ON_RHS!>Inner<!>) return
|
||||
|
||||
if (z is Inner) {
|
||||
z.prop.checkType { _<Any?>() }
|
||||
@@ -26,7 +26,7 @@ class Outer<E> {
|
||||
|
||||
fun bar(x: InnerBase<String>, y: Any?, z: Outer<*>.InnerBase<String>) {
|
||||
x as Inner
|
||||
y as <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Inner<!>
|
||||
y as <!NO_TYPE_ARGUMENTS_ON_RHS!>Inner<!>
|
||||
z as Inner
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ fun testNL1(x: Collection<Int>?): Boolean = x is NL
|
||||
fun testNL2(x: Collection<Int>?): List<Int>? = x as NL
|
||||
fun testNL3(x: Collection<Int>?): List<Int>? = x as NL?
|
||||
|
||||
fun testLStar(x: Collection<Int>): List<Int> = x as <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>LStar<!>
|
||||
fun testMyList(x: Collection<Int>): List<Int> = x as <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>MyList<!>
|
||||
fun testLStar(x: Collection<Int>): List<Int> = x as <!NO_TYPE_ARGUMENTS_ON_RHS!>LStar<!>
|
||||
fun testMyList(x: Collection<Int>): List<Int> = x as <!NO_TYPE_ARGUMENTS_ON_RHS!>MyList<!>
|
||||
|
||||
typealias MMTT<T> = MutableMap<T, T>
|
||||
typealias Dictionary<T> = MutableMap<String, T>
|
||||
@@ -24,8 +24,8 @@ typealias ReadableList<T> = MutableList<out T>
|
||||
|
||||
fun testWrong1(x: Map<Any, Any>) = x is MMTT
|
||||
fun testWrong2(x: Map<Any, Any>) = x is Dictionary
|
||||
fun testWrong3(x: Map<Any, Any>) = x is <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>WriteableMap<!>
|
||||
fun testWrong4(x: List<Any>) = x is <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>ReadableList<!>
|
||||
fun testWrong3(x: Map<Any, Any>) = x is <!NO_TYPE_ARGUMENTS_ON_RHS!>WriteableMap<!>
|
||||
fun testWrong4(x: List<Any>) = x is <!NO_TYPE_ARGUMENTS_ON_RHS!>ReadableList<!>
|
||||
|
||||
fun <T> testLocal(x: Any) {
|
||||
class C
|
||||
|
||||
Reference in New Issue
Block a user