Extract Function: Use intersection type to compute candidate types for parameters
#KT-8103 Fixed
This commit is contained in:
+2
-1
@@ -75,6 +75,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker
|
||||
import org.jetbrains.kotlin.utils.DFS
|
||||
import org.jetbrains.kotlin.utils.DFS.CollectingNodeHandler
|
||||
import org.jetbrains.kotlin.utils.DFS.Neighbors
|
||||
@@ -512,7 +513,7 @@ private class MutableParameter(
|
||||
|
||||
private val defaultType: JetType by Delegates.lazy {
|
||||
writable = false
|
||||
CommonSupertypes.commonSupertype(defaultTypes)
|
||||
TypeUtils.intersect(JetTypeChecker.DEFAULT, defaultTypes)
|
||||
}
|
||||
|
||||
private val parameterTypeCandidates: List<JetType> by Delegates.lazy {
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// PARAM_TYPES: kotlin.String
|
||||
// PARAM_DESCRIPTOR: value-parameter val p: kotlin.Any defined in foo
|
||||
|
||||
fun foo(p: Any) {
|
||||
if (p is String) {
|
||||
<selection>f(p)
|
||||
g(p)</selection>
|
||||
}
|
||||
}
|
||||
|
||||
fun f(s: String){}
|
||||
fun g(o: Any){}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// PARAM_TYPES: kotlin.String
|
||||
// PARAM_DESCRIPTOR: value-parameter val p: kotlin.Any defined in foo
|
||||
|
||||
fun foo(p: Any) {
|
||||
if (p is String) {
|
||||
__dummyTestFun__(p)
|
||||
}
|
||||
}
|
||||
|
||||
private fun __dummyTestFun__(p: String) {
|
||||
f(p)
|
||||
g(p)
|
||||
}
|
||||
|
||||
fun f(s: String){}
|
||||
fun g(o: Any){}
|
||||
+6
@@ -1622,6 +1622,12 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
|
||||
doExtractFunctionTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("multipleTypes.kt")
|
||||
public void testMultipleTypes() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/parameters/candidateTypes/multipleTypes.kt");
|
||||
doExtractFunctionTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nonNullableTypes.kt")
|
||||
public void testNonNullableTypes() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/parameters/candidateTypes/nonNullableTypes.kt");
|
||||
|
||||
Reference in New Issue
Block a user