Provide quickfix for specifying type of variable initialized with null

#KT-23394 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-12-20 15:53:44 +09:00
committed by Yan Zhulanow
parent 55038e19ec
commit cdf7f46ce1
8 changed files with 86 additions and 0 deletions
@@ -0,0 +1,7 @@
// "Change type of 'x' to 'String?'" "true"
fun foo(condition: Boolean) {
var x = null
if (condition) {
x = "abc"<caret>
}
}
@@ -0,0 +1,7 @@
// "Change type of 'x' to 'String?'" "true"
fun foo(condition: Boolean) {
var x: String? = null
if (condition) {
x = "abc"
}
}
@@ -0,0 +1,12 @@
// "Change type of 'x' to 'String?'" "false"
// ACTION: Remove braces from 'if' statement
// ACTION: To raw string literal
// ACTION: Convert assignment to assignment expression
// ERROR: Type mismatch: inferred type is String but Nothing? was expected
// ERROR: Val cannot be reassigned
fun foo(condition: Boolean) {
val x = null
if (condition) {
x = "abc"<caret>
}
}
@@ -0,0 +1,11 @@
// "Change type of 'x' to 'String?'" "false"
// ACTION: Remove braces from 'if' statement
// ACTION: To raw string literal
// ACTION: Convert assignment to assignment expression
// ERROR: Type mismatch: inferred type is String but Int? was expected
fun foo(condition: Boolean) {
var x: Int? = null
if (condition) {
x = "abc"<caret>
}
}
@@ -0,0 +1,11 @@
// "Change type of 'x' to 'String?'" "false"
// ACTION: Remove braces from 'if' statement
// ACTION: To raw string literal
// ACTION: Convert assignment to assignment expression
// ERROR: Type mismatch: inferred type is String but Int was expected
fun foo(condition: Boolean) {
var x = 1
if (condition) {
x = "abc"<caret>
}
}