FIR checker: fix diagnostic parameter renderer

Some of the current renderer is fallbacking to `toString` and output the
fully qualified class name with hash code.
This commit is contained in:
Tianyu Geng
2021-03-16 14:09:09 -07:00
committed by Dmitriy Novozhilov
parent f38c0cf348
commit c198c57e62
14 changed files with 41 additions and 78 deletions
@@ -124,6 +124,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.LOCAL_INTERFACE_N
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.LOCAL_OBJECT_NOT_ALLOWED
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MANY_COMPANION_OBJECTS
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MANY_IMPL_MEMBER_NOT_IMPLEMENTED
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.METHOD_OF_ANY_IMPLEMENTED_IN_INTERFACE
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MISSING_VAL_ON_ANNOTATION_PARAMETER
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MULTIPLE_VARARG_PARAMETERS
@@ -401,7 +402,7 @@ class FirDefaultErrorMessages : DefaultErrorMessages.Extension {
WRONG_NUMBER_OF_TYPE_ARGUMENTS,
"{0,choice,0#No type arguments|1#One type argument|1<{0,number,integer} type arguments} expected for {1}",
null,
TO_STRING
SYMBOL
)
map.put(TYPE_PARAMETERS_IN_OBJECT, "Type parameters are not allowed for objects")
// map.put(ILLEGAL_PROJECTION_USAGE, ...) // &
@@ -485,44 +486,44 @@ class FirDefaultErrorMessages : DefaultErrorMessages.Extension {
ABSTRACT_MEMBER_NOT_IMPLEMENTED,
"{0} is not abstract and does not implement abstract member {1}",
RENDER_CLASS_OR_OBJECT,
FQ_NAMES_IN_TYPES
NAME
)
map.put(
ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED,
"{0} is not abstract and does not implement abstract base class member {1}",
RENDER_CLASS_OR_OBJECT,
FQ_NAMES_IN_TYPES
NAME
)
map.put(
MANY_IMPL_MEMBER_NOT_IMPLEMENTED,
"{0} must override {1} because it inherits many implementations of it",
RENDER_CLASS_OR_OBJECT,
FQ_NAMES_IN_TYPES
NAME
)
map.put(
MANY_IMPL_MEMBER_NOT_IMPLEMENTED,
MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED,
"{0} must override {1} because it inherits multiple interface methods of it",
RENDER_CLASS_OR_OBJECT,
FQ_NAMES_IN_TYPES
NAME
)
map.put(
RETURN_TYPE_MISMATCH_ON_OVERRIDE,
"Return type of ''{0}'' is not a subtype of the return type of the overridden member ''{1}''",
DECLARATION_NAME,
FQ_NAMES_IN_TYPES
DECLARATION_NAME
)
map.put(
PROPERTY_TYPE_MISMATCH_ON_OVERRIDE,
"Type of ''{0}'' is not a subtype of the overridden property ''{1}''",
DECLARATION_NAME,
FQ_NAMES_IN_TYPES
DECLARATION_NAME
)
map.put(
VAR_TYPE_MISMATCH_ON_OVERRIDE,
"Type of ''{0}'' doesn''t match the type of the overridden var-property ''{1}''",
DECLARATION_NAME,
FQ_NAMES_IN_TYPES
DECLARATION_NAME
)
map.put(
+4 -8
View File
@@ -3,16 +3,12 @@ interface A {
fun get(x: Int)
}
class B : A by <error descr="[ABSTRACT_MEMBER_NOT_IMPLEMENTED] Object <anonymous> is not abstract and does not implement abstract member org.jetbrains.kotlin.fir.declarations.impl.FirSimpleFunctionImpl@181a2e4a: public abstract fun /A.get(x: R|kotlin/Int|): R|kotlin/Unit|
">object</error> : A {}
class B : A by <error descr="[ABSTRACT_MEMBER_NOT_IMPLEMENTED] Object <anonymous> is not abstract and does not implement abstract member get">object</error> : A {}
class C : A by (<error descr="[ABSTRACT_MEMBER_NOT_IMPLEMENTED] Object <anonymous> is not abstract and does not implement abstract member org.jetbrains.kotlin.fir.declarations.impl.FirSimpleFunctionImpl@181a2e4a: public abstract fun /A.get(x: R|kotlin/Int|): R|kotlin/Unit|
">object</error> : A {})
class C : A by (<error descr="[ABSTRACT_MEMBER_NOT_IMPLEMENTED] Object <anonymous> is not abstract and does not implement abstract member get">object</error> : A {})
class D : A by 1 <error descr="[NONE_APPLICABLE] None of the following functions are applicable: [kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, ...]">+</error> (<error descr="[ABSTRACT_MEMBER_NOT_IMPLEMENTED] Object <anonymous> is not abstract and does not implement abstract member org.jetbrains.kotlin.fir.declarations.impl.FirSimpleFunctionImpl@181a2e4a: public abstract fun /A.get(x: R|kotlin/Int|): R|kotlin/Unit|
">object</error> : A {})
class D : A by 1 <error descr="[NONE_APPLICABLE] None of the following functions are applicable: [kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, ...]">+</error> (<error descr="[ABSTRACT_MEMBER_NOT_IMPLEMENTED] Object <anonymous> is not abstract and does not implement abstract member get">object</error> : A {})
fun bar() {
val e = object : A by <error descr="[ABSTRACT_MEMBER_NOT_IMPLEMENTED] Object <anonymous> is not abstract and does not implement abstract member org.jetbrains.kotlin.fir.declarations.impl.FirSimpleFunctionImpl@181a2e4a: public abstract fun /A.get(x: R|kotlin/Int|): R|kotlin/Unit|
">object</error> : A {} {}
val e = object : A by <error descr="[ABSTRACT_MEMBER_NOT_IMPLEMENTED] Object <anonymous> is not abstract and does not implement abstract member get">object</error> : A {} {}
}
+4 -8
View File
@@ -15,21 +15,17 @@ package override
class MyChildClass : MyClass() {}
<error descr="[ABSTRACT_MEMBER_NOT_IMPLEMENTED] Class MyIllegalClass is not abstract and does not implement abstract member org.jetbrains.kotlin.fir.declarations.impl.FirSimpleFunctionImpl@dae9e3: public abstract fun override/MyTrait.foo(): R|kotlin/Unit|
">class MyIllegalClass</error> : MyTrait, MyAbstractClass() {}
<error descr="[ABSTRACT_MEMBER_NOT_IMPLEMENTED] Class MyIllegalClass is not abstract and does not implement abstract member foo">class MyIllegalClass</error> : MyTrait, MyAbstractClass() {}
<error descr="[ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED] Class MyIllegalClass2 is not abstract and does not implement abstract base class member org.jetbrains.kotlin.fir.declarations.impl.FirSimpleFunctionImpl@62434f8c: public abstract fun override/MyAbstractClass.bar(): R|kotlin/Unit|
">class MyIllegalClass2</error> : MyTrait, MyAbstractClass() {
<error descr="[ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED] Class MyIllegalClass2 is not abstract and does not implement abstract base class member bar">class MyIllegalClass2</error> : MyTrait, MyAbstractClass() {
override fun foo() {}
}
<error descr="[ABSTRACT_MEMBER_NOT_IMPLEMENTED] Class MyIllegalClass3 is not abstract and does not implement abstract member org.jetbrains.kotlin.fir.declarations.impl.FirSimpleFunctionImpl@dae9e3: public abstract fun override/MyTrait.foo(): R|kotlin/Unit|
">class MyIllegalClass3</error> : MyTrait, MyAbstractClass() {
<error descr="[ABSTRACT_MEMBER_NOT_IMPLEMENTED] Class MyIllegalClass3 is not abstract and does not implement abstract member foo">class MyIllegalClass3</error> : MyTrait, MyAbstractClass() {
override fun bar() {}
}
<error descr="[ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED] Class MyIllegalClass4 is not abstract and does not implement abstract base class member org.jetbrains.kotlin.fir.declarations.impl.FirSimpleFunctionImpl@62434f8c: public abstract fun override/MyAbstractClass.bar(): R|kotlin/Unit|
">class MyIllegalClass4</error> : MyTrait, MyAbstractClass() {
<error descr="[ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED] Class MyIllegalClass4 is not abstract and does not implement abstract base class member bar">class MyIllegalClass4</error> : MyTrait, MyAbstractClass() {
fun foo() {}
override fun other() {}
}
+3 -5
View File
@@ -1,5 +1,3 @@
// IGNORE_FIR
interface Base {
fun foo(): Int
var bar: Int
@@ -7,7 +5,7 @@ interface Base {
}
class Derived : Base {
override fun foo(): <error descr="[RETURN_TYPE_MISMATCH_ON_OVERRIDE] Return type of 'foo' is not a subtype of the return type of the overridden member 'public abstract fun foo(): Int defined in Base'">String</error> = ""
override var bar: <error descr="[VAR_TYPE_MISMATCH_ON_OVERRIDE] Type of 'bar' doesn't match the type of the overridden var-property 'public abstract var bar: Int defined in Base'">String</error> = ""
override val qux: <error descr="[PROPERTY_TYPE_MISMATCH_ON_OVERRIDE] Type of 'qux' is not a subtype of the overridden property 'public abstract val qux: Int defined in Base'">String</error> = ""
override fun foo(): <error descr="[RETURN_TYPE_MISMATCH_ON_OVERRIDE] Return type of 'foo' is not a subtype of the return type of the overridden member 'foo'">String</error> = ""
override var bar: <error descr="[VAR_TYPE_MISMATCH_ON_OVERRIDE] Type of 'bar' doesn't match the type of the overridden var-property 'bar'">String</error> = ""
override val qux: <error descr="[PROPERTY_TYPE_MISMATCH_ON_OVERRIDE] Type of 'qux' is not a subtype of the overridden property 'qux'">String</error> = ""
}
-2
View File
@@ -1,5 +1,3 @@
// IGNORE_FIR
interface Base {
fun foo(): Int
var bar: Int
+2 -4
View File
@@ -1,9 +1,7 @@
// IGNORE_FIR
package foo
open class A<T>
fun <T> f(<warning descr="[UNUSED_PARAMETER] Parameter 't' is never used">t</warning>: T<error descr="[TYPE_ARGUMENTS_NOT_ALLOWED] Type arguments are not allowed for type parameters"><T></error>) {}
fun <T> f(t: <error descr="[TYPE_ARGUMENTS_NOT_ALLOWED] Type arguments are not allowed for type parameters">T<T></error>) {}
fun <T> use(<warning descr="[UNUSED_PARAMETER] Parameter 'b' is never used">b</warning>: foo<error descr="[TYPE_ARGUMENTS_NOT_ALLOWED] Type arguments are not allowed here"><T></error>.A<T>) {}
fun <T> use(b: <error descr="[WRONG_NUMBER_OF_TYPE_ARGUMENTS] One type argument expected for foo/A">foo<T>.A<T></error>) {}
-2
View File
@@ -1,5 +1,3 @@
// IGNORE_FIR
package foo
open class A<T>
+16 -26
View File
@@ -1,43 +1,33 @@
// IGNORE_FIR
package unresolved
class Pair<A, B>(<warning>a</warning>: A, <warning>b</warning>: B)
class Pair<A, B>(a: A, b: B)
fun testGenericArgumentsCount() {
val <warning>p1</warning>: Pair<error><Int></error> = Pair(2, 2)
val <warning>p2</warning>: <error>Pair</error> = Pair(2, 2)
val p1: <error descr="[WRONG_NUMBER_OF_TYPE_ARGUMENTS] 2 type arguments expected for unresolved/Pair">Pair<Int></error> = Pair(2, 2)
val p2: <error descr="[WRONG_NUMBER_OF_TYPE_ARGUMENTS] 2 type arguments expected for unresolved/Pair">Pair</error> = Pair(2, 2)
}
fun testUnresolved() {
if (<error>a</error> is String) {
val <warning>s</warning> = <error>a</error>
if (<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: a">a</error> is String) {
val s = <error descr="[UNRESOLVED_REFERENCE] Unresolved reference: a">a</error>
}
<error>foo</error>(<error>a</error>)
<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: foo">foo</error>(<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: a">a</error>)
val s = "s"
<error>foo</error>(s)
foo1(<error>i</error>)
s.<error>foo</error>()
<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: foo">foo</error>(s)
foo1(<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: i">i</error>)
s.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: foo">foo</error>()
when(<error>a</error>) {
is Int -> <error>a</error>
is String -> <error>a</error>
else -> <error>a</error>
when(<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: a">a</error>) {
is Int -> <error descr="[UNRESOLVED_REFERENCE] Unresolved reference: a">a</error>
is String -> <error descr="[UNRESOLVED_REFERENCE] Unresolved reference: a">a</error>
else -> <error descr="[UNRESOLVED_REFERENCE] Unresolved reference: a">a</error>
}
<<<<<<< Updated upstream
for (j in <error>collection</error>) {
var i: Int = <error>j</error>
i += 1
foo1(<error>j</error>)
}
=======
<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: hasNext"><error descr="[UNRESOLVED_REFERENCE] Unresolved reference: next">for (j in <error descr="[UNRESOLVED_REFERENCE] Unresolved reference: collection">collection</error>) {
<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: hasNext"><error descr="[UNRESOLVED_REFERENCE] Unresolved reference: iterator"><error descr="[UNRESOLVED_REFERENCE] Unresolved reference: next">for (j in <error descr="[UNRESOLVED_REFERENCE] Unresolved reference: collection">collection</error>) {
var i: Int = j
i += 1
foo1(j)
}</error></error>
>>>>>>> Stashed changes
}</error></error></error>
}
fun foo1(<warning>i</warning>: Int) {}
fun foo1(i: Int) {}
-2
View File
@@ -1,5 +1,3 @@
// IGNORE_FIR
package unresolved
class Pair<A, B>(<warning>a</warning>: A, <warning>b</warning>: B)
@@ -1,5 +1,3 @@
// IGNORE_FIR
interface ApplicationFeature<in P : Pipeline<*>, B : Any, V>
open class Pipeline<TSubject : Any>()
fun <A : Pipeline<*>, T : Any, V> A.feature(<warning>feature</warning>: ApplicationFeature<error descr="[WRONG_NUMBER_OF_TYPE_ARGUMENTS] 3 type arguments expected for interface ApplicationFeature<in P : Pipeline<*>, B : Any, V>"><A, T></error>) : Unit {}
@@ -1,9 +1,7 @@
// IGNORE_FIR
package name.that.may.be.very.long
import java.io.Serializable
interface Foo<T> : Comparable<Foo<T>>, Serializable, Cloneable
fun test(<warning>f</warning>: <error descr="[WRONG_NUMBER_OF_TYPE_ARGUMENTS] One type argument expected for interface Foo<T>">Foo</error>) {}
fun test(f: <error descr="[WRONG_NUMBER_OF_TYPE_ARGUMENTS] One type argument expected for name/that/may/be/very/long/Foo">Foo</error>) {}
@@ -1,5 +1,3 @@
// IGNORE_FIR
package name.that.may.be.very.long
import java.io.Serializable
+1 -3
View File
@@ -1,7 +1,5 @@
// IGNORE_FIR
open class A<T>()
class G<T>()
class B : A<<error descr="[WRONG_NUMBER_OF_TYPE_ARGUMENTS] One type argument expected for class G<T>">G</error>>()
class B : A<<error descr="[WRONG_NUMBER_OF_TYPE_ARGUMENTS] One type argument expected for G">G</error>>()
-2
View File
@@ -1,5 +1,3 @@
// IGNORE_FIR
open class A<T>()
class G<T>()