[FIR] Implement UNDERSCORE_IS_RESERVED, UNDERSCORE_USAGE_WITHOUT_BACKTICKS diagnostics (psi only)

This commit is contained in:
Ivan Kochurkin
2021-04-22 14:01:02 +03:00
committed by TeamCityServer
parent cc4adb798f
commit ea2d9f7c0c
30 changed files with 291 additions and 121 deletions
+24 -20
View File
@@ -1,46 +1,50 @@
// !DIAGNOSTICS: -DEPRECATION -TOPLEVEL_TYPEALIASES_ONLY
import kotlin.Deprecated as ___
import kotlin.Deprecated as <!UNDERSCORE_IS_RESERVED!>___<!>
@___("") data class Pair(val x: Int, val y: Int)
class _<________>
val ______ = _<Int>()
class <!UNDERSCORE_IS_RESERVED, UNDERSCORE_IS_RESERVED!>_<!><<!UNDERSCORE_IS_RESERVED!>________<!>>
val <!UNDERSCORE_IS_RESERVED!>______<!> = <!UNDERSCORE_USAGE_WITHOUT_BACKTICKS!>_<!><Int>()
fun __(___: Int, y: _<Int>?): Int {
val (_, z) = Pair(___ - 1, 42)
val (x, __________) = Pair(___ - 1, 42)
val ____ = x
fun <!UNDERSCORE_IS_RESERVED!>__<!>(<!UNDERSCORE_IS_RESERVED!>___<!>: Int, y: <!UNDERSCORE_USAGE_WITHOUT_BACKTICKS!>_<!><Int>?): Int {
val (_, z) = Pair(<!UNDERSCORE_USAGE_WITHOUT_BACKTICKS!>___<!> - 1, 42)
val (x, <!UNDERSCORE_IS_RESERVED!>__________<!>) = Pair(<!UNDERSCORE_USAGE_WITHOUT_BACKTICKS!>___<!> - 1, 42)
val <!UNDERSCORE_IS_RESERVED!>____<!> = x
// in backquotes: allowed
val `_` = __________
val `_` = <!UNDERSCORE_USAGE_WITHOUT_BACKTICKS!>__________<!>
val q = fun(_: Int, __: Int) {}
val q = fun(_: Int, <!UNDERSCORE_IS_RESERVED!>__<!>: Int) {}
q(1, 2)
val _ = 56
val <!UNDERSCORE_IS_RESERVED!>_<!> = 56
fun localFun(_: String) = 1
fun localFun(<!UNDERSCORE_IS_RESERVED!>_<!>: String) = 1
__@ return if (y != null) __(____, y) else __(`_`, ______)
<!UNDERSCORE_IS_RESERVED!>__<!>@ return if (y != null) <!UNDERSCORE_USAGE_WITHOUT_BACKTICKS!>__<!>(<!UNDERSCORE_USAGE_WITHOUT_BACKTICKS!>____<!>, y) else <!UNDERSCORE_USAGE_WITHOUT_BACKTICKS!>__<!>(`_`, <!UNDERSCORE_USAGE_WITHOUT_BACKTICKS!>______<!>)
}
class A1(val _: String)
class A2(_: String) {
class A1(val <!UNDERSCORE_IS_RESERVED, UNDERSCORE_IS_RESERVED!>_<!>: String)
class A2(<!UNDERSCORE_IS_RESERVED!>_<!>: String) {
class B {
typealias _ = CharSequence
typealias <!UNDERSCORE_IS_RESERVED!>_<!> = CharSequence
}
val _: Int = 1
val <!UNDERSCORE_IS_RESERVED!>_<!>: Int = 1
fun _() {}
fun <!UNDERSCORE_IS_RESERVED!>_<!>() {}
fun foo(_: Double) {}
fun foo(<!UNDERSCORE_IS_RESERVED!>_<!>: Double) {}
}
// one underscore parameters for named function are still prohibited
fun oneUnderscore(_: Int) {}
fun oneUnderscore(<!UNDERSCORE_IS_RESERVED!>_<!>: Int) {}
fun doIt(f: (Any?) -> Any?) = f(null)
val something = doIt { __ -> __ }
val something = doIt { <!UNDERSCORE_IS_RESERVED!>__<!> -> <!UNDERSCORE_USAGE_WITHOUT_BACKTICKS!>__<!> }
val something2 = doIt { _ -> 1 }
var p: Int?
get() = null
set(_) {}
+4
View File
@@ -44,3 +44,7 @@ fun doIt(f: (Any?) -> Any?) = f(null)
val something = doIt { <!UNDERSCORE_IS_RESERVED!>__<!> -> <!UNDERSCORE_USAGE_WITHOUT_BACKTICKS!>__<!> }
val something2 = doIt { _ -> 1 }
var p: Int?
get() = null
set(_) {}
@@ -1,42 +0,0 @@
// !DIAGNOSTICS: -DEPRECATION -TOPLEVEL_TYPEALIASES_ONLY
fun test(`_`: Int) {
_ + 1
`_` + 1
}
fun `__`() {}
fun testCall() {
__()
`__`()
}
val testCallableRef = ::__
val testCallableRef2 = ::`__`
object Host {
val `_` = 42
object `__` {
val bar = 4
}
}
val testQualified = Host._
val testQualified2 = Host.`_`
object `___` {
val test = 42
}
val testQualifier = ___.test
val testQualifier2 = `___`.test
val testQualifier3 = Host.__.bar
val testQualifier4 = Host.`__`.bar
fun testCallableRefLHSValue(`_`: Any) = _::toString
fun testCallableRefLHSValue2(`_`: Any) = `_`::toString
val testCallableRefLHSObject = ___::toString
val testCallableRefLHSObject2 = `___`::toString
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -DEPRECATION -TOPLEVEL_TYPEALIASES_ONLY
fun test(`_`: Int) {
@@ -1,11 +0,0 @@
class `___` {
class `____`
}
val testCallableRefLHSType = ___::toString
val testCallableRefLHSType2 = `___`::toString
val testClassLiteralLHSType = ___::class
val testClassLiteralLHSType2 = `___`::class
val tesLHSTypeFQN = `___`.____::class
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
class `___` {
class `____`
}
@@ -1,12 +0,0 @@
// !DIAGNOSTICS: -DEPRECATION -TOPLEVEL_TYPEALIASES_ONLY
class `_`<`__`> {
fun testTypeArgument(x: List<__>) = x
fun testTypeArgument2(x: List<`__`>) = x
}
fun _<Any>.testTypeConstructor() {}
fun `_`<Any>.testTypeConstructor2() {}
val testConstructor = _<Any>()
val testConstructor2 = `_`<Any>()
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -DEPRECATION -TOPLEVEL_TYPEALIASES_ONLY
class `_`<`__`> {
@@ -1,6 +0,0 @@
object Host {
val `____` = { -> }
fun testFunTypeVal() {
____()
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
object Host {
val `____` = { -> }
fun testFunTypeVal() {
@@ -11,39 +11,39 @@ class C {
fun test() {
for ((x, _) in C()) {
foo(x, <!UNRESOLVED_REFERENCE!>_<!>)
foo(x, <!UNDERSCORE_USAGE_WITHOUT_BACKTICKS, UNRESOLVED_REFERENCE!>_<!>)
}
for ((_, y) in C()) {
foo(<!UNRESOLVED_REFERENCE!>_<!>, y)
foo(<!UNDERSCORE_USAGE_WITHOUT_BACKTICKS, UNRESOLVED_REFERENCE!>_<!>, y)
}
for ((_, _) in C()) {
foo(<!UNRESOLVED_REFERENCE!>_<!>, <!UNRESOLVED_REFERENCE!>_<!>)
foo(<!UNDERSCORE_USAGE_WITHOUT_BACKTICKS, UNRESOLVED_REFERENCE!>_<!>, <!UNDERSCORE_USAGE_WITHOUT_BACKTICKS, UNRESOLVED_REFERENCE!>_<!>)
}
for ((_ : Int, _ : String) in C()) {
foo(<!UNRESOLVED_REFERENCE!>_<!>, <!UNRESOLVED_REFERENCE!>_<!>)
foo(<!UNDERSCORE_USAGE_WITHOUT_BACKTICKS, UNRESOLVED_REFERENCE!>_<!>, <!UNDERSCORE_USAGE_WITHOUT_BACKTICKS, UNRESOLVED_REFERENCE!>_<!>)
}
for ((_ : String, _ : Int) in C()) {
foo(<!UNRESOLVED_REFERENCE!>_<!>, <!UNRESOLVED_REFERENCE!>_<!>)
foo(<!UNDERSCORE_USAGE_WITHOUT_BACKTICKS, UNRESOLVED_REFERENCE!>_<!>, <!UNDERSCORE_USAGE_WITHOUT_BACKTICKS, UNRESOLVED_REFERENCE!>_<!>)
}
val (x, _) = A()
val (_, y) = A()
foo(x, y)
foo(x, <!UNRESOLVED_REFERENCE!>_<!>)
foo(<!UNRESOLVED_REFERENCE!>_<!>, y)
foo(x, <!UNDERSCORE_USAGE_WITHOUT_BACKTICKS, UNRESOLVED_REFERENCE!>_<!>)
foo(<!UNDERSCORE_USAGE_WITHOUT_BACKTICKS, UNRESOLVED_REFERENCE!>_<!>, y)
val (`_`, z) = A()
foo(_, z)
foo(<!UNDERSCORE_USAGE_WITHOUT_BACKTICKS!>_<!>, z)
val (_, `_`) = A()
foo(<!ARGUMENT_TYPE_MISMATCH!>_<!>, y)
foo(<!ARGUMENT_TYPE_MISMATCH, UNDERSCORE_USAGE_WITHOUT_BACKTICKS!>_<!>, y)
val (unused, _) = A()
}
@@ -29,7 +29,7 @@ fun foo() {
}
} catch (_: Exception) {
`_`.stackTrace
val y1 = _
val y1 = <!UNDERSCORE_USAGE_WITHOUT_BACKTICKS!>_<!>
val y2 = (`_`)
}
try {
@@ -29,7 +29,7 @@ fun foo() {
}
} catch (_: Exception) {
`_`.stackTrace
val y1 = _
val y1 = <!UNDERSCORE_USAGE_WITHOUT_BACKTICKS!>_<!>
val y2 = (`_`)
}
try {