#KT-27670 Add quick fix: wrap expression in a lambda if compatible functional type is required (#2010)
This commit is contained in:
committed by
Vyacheslav Gerasimov
parent
ed8d9be483
commit
72be9ef738
@@ -0,0 +1,6 @@
|
||||
// "Surround with lambda" "true"
|
||||
fun simple() {
|
||||
str(<caret>"foo")
|
||||
}
|
||||
|
||||
fun str(block: () -> String) {}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Surround with lambda" "true"
|
||||
fun simple() {
|
||||
str({ "foo" })
|
||||
}
|
||||
|
||||
fun str(block: () -> String) {}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Surround with lambda" "true"
|
||||
fun int() {
|
||||
i(<caret>123)
|
||||
}
|
||||
|
||||
fun i(block: () -> Long) {}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Surround with lambda" "true"
|
||||
fun int() {
|
||||
i({ 123 })
|
||||
}
|
||||
|
||||
fun i(block: () -> Long) {}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Surround with lambda" "true"
|
||||
// ERROR: Type mismatch: inferred type is String? but String was expected
|
||||
fun nullableFn() {
|
||||
val nullableStr: String? = null
|
||||
str(<caret>nullableStr)
|
||||
}
|
||||
|
||||
fun str(block: () -> String) {}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Surround with lambda" "true"
|
||||
// ERROR: Type mismatch: inferred type is String? but String was expected
|
||||
fun nullableFn() {
|
||||
val nullableStr: String? = null
|
||||
str({ nullableStr })
|
||||
}
|
||||
|
||||
fun str(block: () -> String) {}
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Surround with lambda" "true"
|
||||
fun subclass() {
|
||||
base(<caret>Leaf())
|
||||
}
|
||||
|
||||
fun base(base: () -> Base) {}
|
||||
|
||||
open class Base {}
|
||||
class Leaf : Base()
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Surround with lambda" "true"
|
||||
fun subclass() {
|
||||
base({ Leaf() })
|
||||
}
|
||||
|
||||
fun base(base: () -> Base) {}
|
||||
|
||||
open class Base {}
|
||||
class Leaf : Base()
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Surround with lambda" "false"
|
||||
// ERROR: Type mismatch: inferred type is Object but () -> String was expected
|
||||
// ACTION: Annotate constructor 'Object'...
|
||||
// ACTION: Change parameter 'block' type of function 'str' to 'Object'
|
||||
// ACTION: Create function 'str'
|
||||
// ACTION: Edit method contract of 'Object'
|
||||
fun fn() {
|
||||
str(<caret>Object())
|
||||
}
|
||||
|
||||
fun str(block: () -> String) {}
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Surround with lambda" "false"
|
||||
// ERROR: Null can not be a value of a non-null type () -> String
|
||||
// ACTION: Change parameter 'block' type of function 'str' to '(() -> String)?'
|
||||
// ACTION: Do not show hints for current method
|
||||
fun nullFn() {
|
||||
str(<caret>null)
|
||||
}
|
||||
|
||||
fun str(block: () -> String) {}
|
||||
Reference in New Issue
Block a user