AA: expected type for expression passed to vararg
This commit is contained in:
committed by
Yan Zhulanow
parent
4f8dad3e4b
commit
4beb55179b
+8
-2
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.components.isVararg
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.returnTypeOrNothing
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.MultipleSmartCasts
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.SingleSmartCast
|
||||
@@ -210,9 +211,14 @@ class KtFe10ExpressionTypeProvider(
|
||||
if (parameterDescriptor != null) {
|
||||
val kotlinType = when (val originalCallableDescriptor = parameterDescriptor.containingDeclaration) {
|
||||
is SamConstructorDescriptor -> originalCallableDescriptor.returnTypeOrNothing
|
||||
else -> parameterDescriptor.type
|
||||
else -> {
|
||||
if (parameterDescriptor.isVararg)
|
||||
parameterDescriptor.varargElementType
|
||||
else
|
||||
parameterDescriptor.type
|
||||
}
|
||||
}
|
||||
return kotlinType.toKtType(analysisContext)
|
||||
return kotlinType?.toKtType(analysisContext)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
@@ -232,6 +232,24 @@ public class Fe10IdeNormalAnalysisSourceModuleExpectedExpressionTypeTestGenerate
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samAsReturn.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samReferenceAsArgument.kt")
|
||||
public void testSamReferenceAsArgument() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samReferenceAsArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samReferenceAsVararg.kt")
|
||||
public void testSamReferenceAsVararg() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samReferenceAsVararg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samReferenceWithTypeCast.kt")
|
||||
public void testSamReferenceWithTypeCast() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samReferenceWithTypeCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samWithExplicitTypeFromProperty.kt")
|
||||
public void testSamWithExplicitTypeFromProperty() throws Exception {
|
||||
|
||||
+5
-1
@@ -167,7 +167,11 @@ internal class KtFirExpressionTypeProvider(
|
||||
arg.psi == argumentExpression
|
||||
}
|
||||
}?.value ?: return null
|
||||
return firParameterForExpression.returnTypeRef.coneType.asKtType()
|
||||
val coneType = firParameterForExpression.returnTypeRef.coneType
|
||||
return if (firParameterForExpression.isVararg)
|
||||
coneType.varargElementType().asKtType()
|
||||
else
|
||||
coneType.asKtType()
|
||||
}
|
||||
|
||||
private fun PsiElement.getFunctionCallAsWithThisAsParameter(): KtCallWithArgument? {
|
||||
|
||||
+18
@@ -232,6 +232,24 @@ public class FirIdeDependentAnalysisSourceModuleExpectedExpressionTypeTestGenera
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samAsReturn.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samReferenceAsArgument.kt")
|
||||
public void testSamReferenceAsArgument() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samReferenceAsArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samReferenceAsVararg.kt")
|
||||
public void testSamReferenceAsVararg() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samReferenceAsVararg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samReferenceWithTypeCast.kt")
|
||||
public void testSamReferenceWithTypeCast() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samReferenceWithTypeCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samWithExplicitTypeFromProperty.kt")
|
||||
public void testSamWithExplicitTypeFromProperty() throws Exception {
|
||||
|
||||
+18
@@ -232,6 +232,24 @@ public class FirIdeNormalAnalysisSourceModuleExpectedExpressionTypeTestGenerated
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samAsReturn.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samReferenceAsArgument.kt")
|
||||
public void testSamReferenceAsArgument() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samReferenceAsArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samReferenceAsVararg.kt")
|
||||
public void testSamReferenceAsVararg() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samReferenceAsVararg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samReferenceWithTypeCast.kt")
|
||||
public void testSamReferenceWithTypeCast() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samReferenceWithTypeCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samWithExplicitTypeFromProperty.kt")
|
||||
public void testSamWithExplicitTypeFromProperty() throws Exception {
|
||||
|
||||
+18
@@ -232,6 +232,24 @@ public class FirStandaloneNormalAnalysisSourceModuleExpectedExpressionTypeTestGe
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samAsReturn.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samReferenceAsArgument.kt")
|
||||
public void testSamReferenceAsArgument() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samReferenceAsArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samReferenceAsVararg.kt")
|
||||
public void testSamReferenceAsVararg() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samReferenceAsVararg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samReferenceWithTypeCast.kt")
|
||||
public void testSamReferenceWithTypeCast() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samReferenceWithTypeCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samWithExplicitTypeFromProperty.kt")
|
||||
public void testSamWithExplicitTypeFromProperty() throws Exception {
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun dummy() = Any()
|
||||
|
||||
fun runRunnable(r : java.lang.Runnable) = r()
|
||||
|
||||
fun test() {
|
||||
runRunnable(:<caret>:dummy)
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
expression: ::dummy
|
||||
expected type: java/lang/Runnable
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fun dummy() = Any()
|
||||
|
||||
fun runRunnables(vararg rs : java.lang.Runnable) {
|
||||
rs.forEach {
|
||||
it.run()
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
runRunnables(:<caret>:dummy)
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
expression: ::dummy
|
||||
expected type: java/lang/Runnable
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
fun dummy() = Any()
|
||||
|
||||
fun test() {
|
||||
:<caret>:dummy as java.lang.Runnable
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
expression: ::dummy
|
||||
expected type: java/lang/Runnable
|
||||
Reference in New Issue
Block a user