Front-end fix: result type corrected for increment / decrement expressions. Smart cast allowed on a postfix increment result. See KT-7561.
Now result type is receiver type for postfix increment, or increment result type for prefix increment. A set of relevant tests.
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
class MyClass
|
||||
|
||||
// In principle it is not correct, MyClass? is not a subtype of MyClass
|
||||
fun MyClass.inc(): MyClass? { return null }
|
||||
|
||||
public fun box() : MyClass? {
|
||||
var i : MyClass?
|
||||
i = MyClass()
|
||||
// type of j can be inferred as MyClass()
|
||||
var j = <!DEBUG_INFO_SMARTCAST!>i<!>++
|
||||
<!DEBUG_INFO_SMARTCAST!>j<!>.hashCode()
|
||||
return i
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
public fun box(): MyClass?
|
||||
internal fun MyClass.inc(): MyClass?
|
||||
|
||||
internal final class MyClass {
|
||||
public constructor MyClass()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
class MyClass
|
||||
|
||||
// Correct at compile time but wrong at run-time
|
||||
fun MyClass?.inc(): MyClass? { return null }
|
||||
|
||||
public fun box() : MyClass? {
|
||||
var i : MyClass?
|
||||
i = MyClass()
|
||||
var j = i++
|
||||
<!DEBUG_INFO_SMARTCAST!>j<!>.hashCode()
|
||||
return i
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
public fun box(): MyClass?
|
||||
internal fun MyClass?.inc(): MyClass?
|
||||
|
||||
internal final class MyClass {
|
||||
public constructor MyClass()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun Int?.inc(): Int? { return this }
|
||||
|
||||
public fun box(arg: Int?) : Int? {
|
||||
var i : Int? = arg
|
||||
var j = i++
|
||||
j<!UNSAFE_CALL!>.<!>toInt()
|
||||
return i
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public fun box(/*0*/ arg: kotlin.Int?): kotlin.Int?
|
||||
internal fun kotlin.Int?.inc(): kotlin.Int?
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
class MyClass
|
||||
|
||||
// In principle it is not correct, MyClass? is not a subtype of MyClass
|
||||
fun MyClass.inc(): MyClass? { return null }
|
||||
|
||||
public fun box() {
|
||||
var i : MyClass?
|
||||
i = MyClass()
|
||||
// Type of j should be inferred as MyClass?
|
||||
var j = ++<!DEBUG_INFO_SMARTCAST!>i<!>
|
||||
// j is null so call is unsafe
|
||||
j<!UNSAFE_CALL!>.<!>hashCode()
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
public fun box(): kotlin.Unit
|
||||
internal fun MyClass.inc(): MyClass?
|
||||
|
||||
internal final class MyClass {
|
||||
public constructor MyClass()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
class MyClass
|
||||
|
||||
// Correct at compile time but wrong at run-time
|
||||
fun MyClass?.inc(): MyClass? { return null }
|
||||
|
||||
public fun box() {
|
||||
var i : MyClass?
|
||||
i = MyClass()
|
||||
// type of j should be MyClass?
|
||||
var j = ++i
|
||||
// j is null so call should be unsafe
|
||||
j<!UNSAFE_CALL!>.<!>hashCode()
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
public fun box(): kotlin.Unit
|
||||
internal fun MyClass?.inc(): MyClass?
|
||||
|
||||
internal final class MyClass {
|
||||
public constructor MyClass()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun Int?.inc(): Int? { return this }
|
||||
|
||||
public fun box(arg: Int?) : Int? {
|
||||
var i = arg
|
||||
var j = ++i
|
||||
j<!UNSAFE_CALL!>.<!>toInt()
|
||||
return ++j
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public fun box(/*0*/ arg: kotlin.Int?): kotlin.Int?
|
||||
internal fun kotlin.Int?.inc(): kotlin.Int?
|
||||
Reference in New Issue
Block a user