Files
kotlin-fork/compiler/fir/analysis-tests/testData/resolve/expresssions/access.kt
T
Tianyu Geng d6907222cd FIR: pass the qualified access source when reporting ErrorNamedReference
Currently if there is an error in a function call, FIR would report the
entire expression if this call is qualified, but *only* the name if it's
not qualified. For example, assume the following two calls are all
contains some errors.

```
a.foo(1,2,3)
^^^^^^^^^^^^
bar(1,2,3)
^^^
```

The entire call of `foo` is reported since it's qualified. But only the
reference `bar` is reported since it's not qualified. This limits the
usage of position strategies because the IDE does not allow position
strategies to go outside of the initially reported PSI element
(org.jetbrains.kotlin.idea.fir.highlighter.KotlinHighLevelDiagnosticHighlightingPass#addDiagnostic).

This change passes both the original error named reference and the
surrounding qualified access expression and defer the decision of which
to use to the reporting logic.

For unresolved reference and checks on `super` keyword, the position
strategy should not highlight the surrounding parentheses. Hence a new
position strategy `REFERENCED_NAME_BY_QUALIFIED` is added.

In addition, this change also has the following side effect

* some diagnostics are no longer reported when there is a syntax error
  since the higher level structure does not exist when there is a syntax
  error
2021-03-29 12:45:27 +03:00

64 lines
902 B
Kotlin
Vendored

class Foo {
val x = 1
fun abc() = x
fun cba() = abc()
}
class Bar {
val x = ""
// NB: unused
fun Foo.abc() = x
fun bar(): Bar = this
// NB: unused
operator fun String.plus(bar: Bar): String {
return ""
}
// NB! abc() here is resolved to member Foo.abc(), and not to extension member of 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()
}
fun Foo.ext() = x
fun bar() {
}
fun buz() {
bar()
}
fun f() {
val a = 10
val b = a
val d = ""
val c = <!UNRESOLVED_REFERENCE!>c<!>
<!UNRESOLVED_REFERENCE!>abc<!>()
fun bcd() {}
fun abc() {
val a = d
val b = a
bcd()
fun dcb() {}
dcb()
}
<!UNRESOLVED_REFERENCE!>dcb<!>()
abc()
}