[FIR] Improve diagnostic reporting & don't use error symbol for candidate if possible

Also introduce few new diagnostics:
- NONE_APPLICABLE more many inapplicable candidates
- HIDDEN for visible candidates
This commit is contained in:
Dmitriy Novozhilov
2020-07-22 16:40:14 +03:00
committed by Mikhail Glukhikh
parent 5c0528b61e
commit f283f2db43
365 changed files with 1400 additions and 1451 deletions
@@ -8,7 +8,7 @@ class CallBasedInExpressionGenerator(
private val isInverted = operatorReference.<!UNRESOLVED_REFERENCE!>getReferencedNameElementType<!>() == <!UNRESOLVED_REFERENCE!>KtTokens<!>.<!UNRESOLVED_REFERENCE!>NOT_IN<!>
override fun generate(argument: StackValue): BranchedValue =
gen(argument).<!INAPPLICABLE_CANDIDATE!>let<!> { if (isInverted) <!UNRESOLVED_REFERENCE!>Invert<!>(<!UNRESOLVED_REFERENCE!>it<!>) else <!UNRESOLVED_REFERENCE!>it<!> }
gen(argument).<!INAPPLICABLE_CANDIDATE!>let<!> { if (isInverted) <!UNRESOLVED_REFERENCE!>Invert<!>(it) else it }
private fun gen(argument: StackValue): BranchedValue =
object : BranchedValue(argument, null, argument.<!UNRESOLVED_REFERENCE!>type<!>, <!UNRESOLVED_REFERENCE!>Opcodes<!>.<!UNRESOLVED_REFERENCE!>IFEQ<!>) {
@@ -27,4 +27,4 @@ class CallBasedInExpressionGenerator(
result.<!UNRESOLVED_REFERENCE!>put<!>(result.<!UNRESOLVED_REFERENCE!>type<!>, result.<!UNRESOLVED_REFERENCE!>kotlinType<!>, v)
}
}
}
}
@@ -14,13 +14,13 @@ FILE: CallBasedInExpressionGenerator.kt
private get(): R|kotlin/Boolean|
public final override fun generate(argument: R|ERROR CLASS: Symbol not found, for `StackValue`|): R|ERROR CLASS: Symbol not found, for `BranchedValue`| {
^generate this@R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator|.R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator.gen|(R|<local>/argument|).<Inapplicable(WRONG_RECEIVER): [kotlin/let]>#(<L> = let@fun <anonymous>(): <ERROR TYPE REF: Can't resolve when expression> {
^generate this@R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator|.R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator.gen|(R|<local>/argument|).<Inapplicable(WRONG_RECEIVER): kotlin/let>#<R|kotlin/Any?|, R|kotlin/Nothing|>(<L> = let@fun <anonymous>(it: R|kotlin/Any?|): <ERROR TYPE REF: Can't resolve when expression> <kind=EXACTLY_ONCE> {
^ when () {
this@R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator|.R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator.isInverted| -> {
<Unresolved name: Invert>#(<Unresolved name: it>#)
<Unresolved name: Invert>#(R|<local>/it|)
}
else -> {
<Unresolved name: it>#
R|<local>/it|
}
}
@@ -21,7 +21,7 @@ class Bar {
}
// NB! abc() here is resolved to member Foo.abc(), and not to extension member of Bar
fun Foo.check() = abc() <!INAPPLICABLE_CANDIDATE!>+<!> bar()
fun Foo.check() = abc() <!NONE_APPLICABLE!>+<!> bar()
// NB! + here is resolved to member String.plus (not to extension member above)
fun Foo.check2() = "" + bar()
@@ -60,4 +60,4 @@ fun f() {
<!UNRESOLVED_REFERENCE!>dcb<!>()
abc()
}
}
@@ -36,8 +36,8 @@ FILE: access.kt
^plus String()
}
public final fun R|Foo|.check(): <ERROR TYPE REF: Inapplicable(INAPPLICABLE): [kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus]> {
^check this@R|/Bar.check|.R|/Foo.abc|().<Inapplicable(INAPPLICABLE): [kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus]>#(this@R|/Bar|.R|/Bar.bar|())
public final fun R|Foo|.check(): <ERROR TYPE REF: Ambiguity: plus, [kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus]> {
^check this@R|/Bar.check|.R|/Foo.abc|().<Ambiguity: plus, [kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus]>#(this@R|/Bar|.R|/Bar.bar|())
}
public final fun R|Foo|.check2(): R|kotlin/String| {
@@ -34,5 +34,5 @@ FILE: enumEntryUse.kt
R|/useEnum|(Q|TestEnum|.R|/TestEnum.SECOND|)
R|/useEnum|(Q|TestEnum|.R|/TestEnum.THIRD|)
R|/useVararg|(vararg(Q|TestEnum|.R|/TestEnum.FIRST|, Q|TestEnum|.R|/TestEnum.SECOND|))
<Inapplicable(INAPPLICABLE): [/useVararg]>#(Int(1), Int(2), Int(3), Int(4), Int(5))
<Inapplicable(INAPPLICABLE): /useVararg>#(Int(1), Int(2), Int(3), Int(4), Int(5))
}
@@ -18,5 +18,5 @@ FILE: typeParameters.kt
}
public final fun main(fooImpl: R|FooImpl|, bar: R|Bar|): R|kotlin/Unit| {
lval a: R|FooImpl| = R|/foo|<R|FooImpl|>(R|<local>/fooImpl|)
lval b: <ERROR TYPE REF: Inapplicable(INAPPLICABLE): [/foo]> = <Inapplicable(INAPPLICABLE): [/foo]>#(R|<local>/bar|)
lval b: R|Bar| = <Inapplicable(INAPPLICABLE): /foo>#<R|Bar|>(R|<local>/bar|)
}
@@ -17,6 +17,6 @@ FILE: typeParameters2.kt
^foo R|<local>/t|
}
public final fun main(fooImpl: R|FooImpl|, fooBarImpl: R|FooBarImpl|): R|kotlin/Unit| {
lval a: <ERROR TYPE REF: Inapplicable(INAPPLICABLE): [/foo]> = <Inapplicable(INAPPLICABLE): [/foo]>#(R|<local>/fooBarImpl|)
lval a: R|FooImpl| = <Inapplicable(INAPPLICABLE): /foo>#<R|FooImpl|>(R|<local>/fooBarImpl|)
lval b: R|Foo| = R|/foo|<R|Foo|>(R|<local>/fooImpl|)
}
@@ -11,8 +11,8 @@ open class Outer {
class Derived : Outer() {
fun foo() {
Outer.<!INAPPLICABLE_CANDIDATE!>PrivateNested<!>()
super.<!INAPPLICABLE_CANDIDATE!>PrivateInner<!>()
Outer.<!HIDDEN!>PrivateNested<!>()
super.<!HIDDEN!>PrivateInner<!>()
Outer.ProtectedNested()
super.ProtectedInner()
@@ -23,11 +23,11 @@ class Derived : Outer() {
}
fun foo() {
Outer.<!INAPPLICABLE_CANDIDATE!>PrivateNested<!>()
Outer().<!INAPPLICABLE_CANDIDATE!>PrivateInner<!>()
Outer.<!HIDDEN!>PrivateNested<!>()
Outer().<!HIDDEN!>PrivateInner<!>()
Outer.<!INAPPLICABLE_CANDIDATE!>ProtectedNested<!>()
Outer().<!INAPPLICABLE_CANDIDATE!>ProtectedInner<!>()
Outer.<!HIDDEN!>ProtectedNested<!>()
Outer().<!HIDDEN!>ProtectedInner<!>()
Outer.PublicNested()
Outer().PublicInner()
@@ -53,8 +53,8 @@ FILE: nestedVisibility.kt
}
public final fun foo(): R|kotlin/Unit| {
Q|Outer|.<Inapplicable(HIDDEN): [/Outer.PrivateNested.PrivateNested]>#()
this@R|/Derived|.super<R|Outer|>.<Inapplicable(HIDDEN): [/Outer.PrivateInner.PrivateInner]>#()
Q|Outer|.<HIDDEN: /Outer.PrivateNested.PrivateNested is invisible>#()
this@R|/Derived|.super<R|Outer|>.<HIDDEN: /Outer.PrivateInner.PrivateInner is invisible>#()
Q|Outer|.R|/Outer.ProtectedNested.ProtectedNested|()
this@R|/Derived|.super<R|Outer|>.R|/Outer.ProtectedInner.ProtectedInner|()
Q|Outer|.R|/Outer.PublicNested.PublicNested|()
@@ -63,10 +63,10 @@ FILE: nestedVisibility.kt
}
public final fun foo(): R|kotlin/Unit| {
Q|Outer|.<Inapplicable(HIDDEN): [/Outer.PrivateNested.PrivateNested]>#()
R|/Outer.Outer|().<Inapplicable(HIDDEN): [/Outer.PrivateInner.PrivateInner]>#()
Q|Outer|.<Inapplicable(HIDDEN): [/Outer.ProtectedNested.ProtectedNested]>#()
R|/Outer.Outer|().<Inapplicable(HIDDEN): [/Outer.ProtectedInner.ProtectedInner]>#()
Q|Outer|.<HIDDEN: /Outer.PrivateNested.PrivateNested is invisible>#()
R|/Outer.Outer|().<HIDDEN: /Outer.PrivateInner.PrivateInner is invisible>#()
Q|Outer|.<HIDDEN: /Outer.ProtectedNested.ProtectedNested is invisible>#()
R|/Outer.Outer|().<HIDDEN: /Outer.ProtectedInner.ProtectedInner is invisible>#()
Q|Outer|.R|/Outer.PublicNested.PublicNested|()
R|/Outer.Outer|().R|/Outer.PublicInner.PublicInner|()
}
@@ -9,21 +9,21 @@ private class Private {
bar()
Nested()
fromCompanion()
NotCompanion.<!INAPPLICABLE_CANDIDATE!>foo<!>() // hidden
NotCompanion.<!HIDDEN!>foo<!>() // hidden
}
inner class Inner {
fun foo() {
bar()
fromCompanion()
NotCompanion.<!INAPPLICABLE_CANDIDATE!>foo<!>() // hidden
NotCompanion.<!HIDDEN!>foo<!>() // hidden
}
}
private class Nested {
fun foo() {
fromCompanion()
NotCompanion.<!INAPPLICABLE_CANDIDATE!>foo<!>() // hidden
NotCompanion.<!HIDDEN!>foo<!>() // hidden
}
}
@@ -54,7 +54,7 @@ fun withLocals() {
Local().baz()
Local().<!INAPPLICABLE_CANDIDATE!>bar<!>() // hidden
Local().<!HIDDEN!>bar<!>() // hidden
}
fun test() {
@@ -62,14 +62,14 @@ fun test() {
Private().baz()
Private().Inner()
Private().<!INAPPLICABLE_CANDIDATE!>bar<!>() // hidden
Private.<!INAPPLICABLE_CANDIDATE!>Nested<!>() // hidden
Private.<!INAPPLICABLE_CANDIDATE!>fromCompanion<!>() // hidden
Private().<!HIDDEN!>bar<!>() // hidden
Private.<!HIDDEN!>Nested<!>() // hidden
Private.<!HIDDEN!>fromCompanion<!>() // hidden
}
// FILE: second.kt
fun secondTest() {
<!INAPPLICABLE_CANDIDATE!>foo<!>() // hidden
<!INAPPLICABLE_CANDIDATE!>Private<!>() // hidden
}
<!HIDDEN!>foo<!>() // hidden
<!HIDDEN!>Private<!>() // hidden
}
@@ -13,7 +13,7 @@ FILE: first.kt
this@R|/Private|.R|/Private.bar|()
R|/Private.Nested.Nested|()
this@R|/Private.Companion|.R|/Private.Companion.fromCompanion|()
Q|Private.NotCompanion|.<Inapplicable(HIDDEN): [/Private.NotCompanion.foo]>#()
Q|Private.NotCompanion|.<HIDDEN: /Private.NotCompanion.foo is invisible>#()
}
public[private] final inner class Inner : R|kotlin/Any| {
@@ -24,7 +24,7 @@ FILE: first.kt
public[private] final fun foo(): R|kotlin/Unit| {
this@R|/Private|.R|/Private.bar|()
this@R|/Private.Companion|.R|/Private.Companion.fromCompanion|()
Q|Private.NotCompanion|.<Inapplicable(HIDDEN): [/Private.NotCompanion.foo]>#()
Q|Private.NotCompanion|.<HIDDEN: /Private.NotCompanion.foo is invisible>#()
}
}
@@ -36,7 +36,7 @@ FILE: first.kt
public[private] final fun foo(): R|kotlin/Unit| {
this@R|/Private.Companion|.R|/Private.Companion.fromCompanion|()
Q|Private.NotCompanion|.<Inapplicable(HIDDEN): [/Private.NotCompanion.foo]>#()
Q|Private.NotCompanion|.<HIDDEN: /Private.NotCompanion.foo is invisible>#()
}
}
@@ -89,18 +89,18 @@ FILE: first.kt
}
R|/Local.Local|().R|/Local.baz|()
R|/Local.Local|().<Inapplicable(HIDDEN): [/Local.bar]>#()
R|/Local.Local|().<HIDDEN: /Local.bar is invisible>#()
}
public final fun test(): R|kotlin/Unit| {
R|/foo|()
R|/Private.Private|().R|/Private.baz|()
R|/Private.Private|().R|/Private.Inner.Inner|()
R|/Private.Private|().<Inapplicable(HIDDEN): [/Private.bar]>#()
Q|Private|.<Inapplicable(HIDDEN): [/Private.Nested.Nested]>#()
Q|Private|.<Inapplicable(HIDDEN): [/Private.Companion.fromCompanion]>#()
R|/Private.Private|().<HIDDEN: /Private.bar is invisible>#()
Q|Private|.<HIDDEN: /Private.Nested.Nested is invisible>#()
Q|Private|.<HIDDEN: /Private.Companion.fromCompanion is invisible>#()
}
FILE: second.kt
public final fun secondTest(): R|kotlin/Unit| {
<Inapplicable(HIDDEN): [/foo]>#()
<Inapplicable(HIDDEN): [/Private.Private]>#()
<HIDDEN: /foo is invisible>#()
<HIDDEN: /Private.Private is invisible>#()
}
@@ -31,7 +31,7 @@ class Derived : Protected() {
fun foo() {
bar()
Nested().foo()
Nested().<!INAPPLICABLE_CANDIDATE!>bar<!>() // hidden
Nested().<!HIDDEN!>bar<!>() // hidden
fromCompanion()
protectedFromCompanion()
@@ -48,8 +48,8 @@ fun test() {
Protected().baz()
Protected().Inner()
Protected().<!INAPPLICABLE_CANDIDATE!>bar<!>() // hidden
Protected.<!INAPPLICABLE_CANDIDATE!>Nested<!>() // hidden
Protected().<!HIDDEN!>bar<!>() // hidden
Protected.<!HIDDEN!>Nested<!>() // hidden
}
open class Generic<T>(val x: T) {
@@ -59,7 +59,7 @@ FILE: protectedVisibility.kt
public final fun foo(): R|kotlin/Unit| {
this@R|/Derived|.R|/Protected.bar|()
R|/Protected.Nested.Nested|().R|/Protected.Nested.foo|()
R|/Protected.Nested.Nested|().<Inapplicable(HIDDEN): [/Protected.Nested.bar]>#()
R|/Protected.Nested.Nested|().<HIDDEN: /Protected.Nested.bar is invisible>#()
this@R|/Protected.Companion|.R|/Protected.Companion.fromCompanion|()
this@R|/Protected.Companion|.R|/Protected.Companion.protectedFromCompanion|()
}
@@ -79,8 +79,8 @@ FILE: protectedVisibility.kt
public final fun test(): R|kotlin/Unit| {
R|/Protected.Protected|().R|/Protected.baz|()
R|/Protected.Protected|().R|/Protected.Inner.Inner|()
R|/Protected.Protected|().<Inapplicable(HIDDEN): [/Protected.bar]>#()
Q|Protected|.<Inapplicable(HIDDEN): [/Protected.Nested.Nested]>#()
R|/Protected.Protected|().<HIDDEN: /Protected.bar is invisible>#()
Q|Protected|.<HIDDEN: /Protected.Nested.Nested is invisible>#()
}
public open class Generic<T> : R|kotlin/Any| {
public constructor<T>(x: R|T|): R|Generic<T>| {
@@ -36,7 +36,7 @@ FILE: test.kt
lval bar: R|kotlin/CharSequence?| = R|<local>/x|?.{ $subj$.R|/SomeClass.bar| }
when () {
!=(R|<local>/bar|, Null(null)) -> {
R|<local>/x|.R|/SomeClass.bar|.<Inapplicable(WRONG_RECEIVER): [kotlin/CharSequence.length]>#
R|<local>/x|.R|/SomeClass.bar|.<Inapplicable(WRONG_RECEIVER): kotlin/CharSequence.length>#
}
}