[FIR] Desugar increment/decrement in body resolve phase
The expression needs to be resolved first to determine if there is a receiver that needs to be extracted to a temporary variable. Also, the special case for prefix increment/decrement on local variable without delegates requires resolution to check if the variable is local. ^KT-56771 Fixed ^KT-56659 Fixed
This commit is contained in:
committed by
Space Team
parent
5ecf9cce25
commit
3b9724d20e
+4
-4
@@ -22,9 +22,9 @@ class WrongIncDec() {
|
||||
|
||||
fun testWrongIncDec() {
|
||||
var x = WrongIncDec()
|
||||
<!RESULT_TYPE_MISMATCH!>x++<!>
|
||||
x<!RESULT_TYPE_MISMATCH!>++<!>
|
||||
<!RESULT_TYPE_MISMATCH!>++x<!>
|
||||
<!RESULT_TYPE_MISMATCH!>x--<!>
|
||||
x<!RESULT_TYPE_MISMATCH!>--<!>
|
||||
<!RESULT_TYPE_MISMATCH!>--x<!>
|
||||
}
|
||||
|
||||
@@ -41,6 +41,6 @@ fun testUnitIncDec() {
|
||||
<!INC_DEC_SHOULD_NOT_RETURN_UNIT!>--<!>x
|
||||
x = x<!INC_DEC_SHOULD_NOT_RETURN_UNIT!>++<!>
|
||||
x = x<!INC_DEC_SHOULD_NOT_RETURN_UNIT!>--<!>
|
||||
x = <!INC_DEC_SHOULD_NOT_RETURN_UNIT!>++<!>x
|
||||
x = <!INC_DEC_SHOULD_NOT_RETURN_UNIT!>--<!>x
|
||||
x = <!INC_DEC_SHOULD_NOT_RETURN_UNIT, INC_DEC_SHOULD_NOT_RETURN_UNIT!>++<!>x
|
||||
x = <!INC_DEC_SHOULD_NOT_RETURN_UNIT, INC_DEC_SHOULD_NOT_RETURN_UNIT!>--<!>x
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ class Test() {
|
||||
|
||||
fun testIncompleteSyntax() {
|
||||
val s = "s"
|
||||
<!UNRESOLVED_REFERENCE!>++<!>s.<!SYNTAX!><!>
|
||||
<!UNRESOLVED_REFERENCE!>++<!><!VARIABLE_EXPECTED!>s<!>.<!SYNTAX!><!>
|
||||
}
|
||||
|
||||
fun testVariables() {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// SKIP_TXT
|
||||
// FIR_IDENTICAL
|
||||
|
||||
package foo.bar
|
||||
|
||||
var baz = 1
|
||||
|
||||
fun test() {
|
||||
foo.bar.baz++
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// SKIP_TXT
|
||||
// ISSUE: KT-56659
|
||||
|
||||
object AAA { operator fun inc(): AAA = this }
|
||||
|
||||
fun test1() {
|
||||
<!VARIABLE_EXPECTED!>AAA<!>++
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
++<!VARIABLE_EXPECTED!>AAA<!>
|
||||
}
|
||||
|
||||
fun test3() {
|
||||
var x = AAA
|
||||
x = <!VARIABLE_EXPECTED!>AAA<!>++
|
||||
}
|
||||
|
||||
fun test4() {
|
||||
var x = AAA
|
||||
x = ++<!VARIABLE_EXPECTED!>AAA<!>
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// SKIP_TXT
|
||||
// ISSUE: KT-56659
|
||||
|
||||
object AAA { operator fun inc(): AAA = this }
|
||||
|
||||
fun test1() {
|
||||
<!VAL_REASSIGNMENT!>AAA<!>++
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
++<!VAL_REASSIGNMENT!>AAA<!>
|
||||
}
|
||||
|
||||
fun test3() {
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>x<!> = AAA
|
||||
x = <!VAL_REASSIGNMENT!>AAA<!>++
|
||||
}
|
||||
|
||||
fun test4() {
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>x<!> = AAA
|
||||
x = ++<!VAL_REASSIGNMENT!>AAA<!>
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -VAL_REASSIGNMENT -UNUSED_CHANGED_VALUE -VARIABLE_EXPECTED
|
||||
|
||||
inline operator fun <T, V> Function1<T, V>.unaryPlus() = this
|
||||
operator fun <T, V> Function1<T, V>.unaryMinus() = this
|
||||
inline operator fun <T, V> Function1<T, V>.inc() = this
|
||||
operator fun <T, V> Function1<T, V>.dec() = this
|
||||
|
||||
inline operator fun <T, V> @ExtensionFunctionType Function2<T, T, V>.unaryPlus(){}
|
||||
operator fun <T, V> @ExtensionFunctionType Function2<T, T, V>.unaryMinus(){}
|
||||
inline operator fun <T, V> @ExtensionFunctionType Function2<T, T, V>.inc() = this
|
||||
operator fun <T, V> @ExtensionFunctionType Function2<T, T, V>.dec() = this
|
||||
|
||||
inline fun <T, V> inlineFunWithInvoke(s: (p: T) -> V, ext: T.(p: T) -> V) {
|
||||
+<!USAGE_IS_NOT_INLINABLE!>s<!>
|
||||
-<!USAGE_IS_NOT_INLINABLE!>s<!>
|
||||
<!USAGE_IS_NOT_INLINABLE!>s<!>++
|
||||
<!USAGE_IS_NOT_INLINABLE!>++<!><!USAGE_IS_NOT_INLINABLE!>s<!>
|
||||
<!USAGE_IS_NOT_INLINABLE!>s<!>--
|
||||
<!USAGE_IS_NOT_INLINABLE!>--<!><!USAGE_IS_NOT_INLINABLE!>s<!>
|
||||
+<!USAGE_IS_NOT_INLINABLE!>ext<!>
|
||||
-<!USAGE_IS_NOT_INLINABLE!>ext<!>
|
||||
<!USAGE_IS_NOT_INLINABLE!>ext<!>++
|
||||
<!USAGE_IS_NOT_INLINABLE!>++<!><!USAGE_IS_NOT_INLINABLE!>ext<!>
|
||||
<!USAGE_IS_NOT_INLINABLE!>ext<!>--
|
||||
<!USAGE_IS_NOT_INLINABLE!>--<!><!USAGE_IS_NOT_INLINABLE!>ext<!>
|
||||
}
|
||||
|
||||
inline fun <T, V> Function1<T, V>.inlineFunWithInvoke() {
|
||||
+this
|
||||
-this
|
||||
this++
|
||||
++this
|
||||
this--
|
||||
--this
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -VAL_REASSIGNMENT -UNUSED_CHANGED_VALUE -VARIABLE_EXPECTED
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ open class A {
|
||||
fun foo() {
|
||||
<!UNRESOLVED_REFERENCE!>topLevelFun<!>()
|
||||
<!UNRESOLVED_REFERENCE!>topLevelFun<!>(1)
|
||||
<!UNRESOLVED_REFERENCE!>topLevelProperty<!><!UNRESOLVED_REFERENCE!>++<!>
|
||||
<!UNRESOLVED_REFERENCE!>topLevelProperty<!><!UNRESOLVED_REFERENCE, UNRESOLVED_REFERENCE, UNRESOLVED_REFERENCE, UNRESOLVED_REFERENCE!>++<!>
|
||||
"".<!UNRESOLVED_REFERENCE!>topLevelExtensionFun<!>()
|
||||
1.<!UNRESOLVED_REFERENCE!>topLevelExtensionFun<!>()
|
||||
"".<!UNRESOLVED_REFERENCE!>topLevelExtensionProperty<!>
|
||||
|
||||
Reference in New Issue
Block a user