Commit 4337d907 authored by Jinseong Jeon's avatar Jinseong Jeon
Browse files

FIR/UAST: regression test for UCallExpression#getArgumentForParameter

...when argument is a smartcasted expression

If not retrieved, SameParameterValueInspection made a false positive
that the actual value of the corresponding parameter is always null.

^KTIJ-25112
parent 4f969664
Showing with 32 additions and 0 deletions
+32 -0
...@@ -41,6 +41,30 @@ interface UastApiFixtureTestBase : UastPluginSelection { ...@@ -41,6 +41,30 @@ interface UastApiFixtureTestBase : UastPluginSelection {
) )
} }
fun checkArgumentForParameter_smartcast(myFixture: JavaCodeInsightTestFixture) {
myFixture.configureByText(
"main.kt", """
open class A
class B : A()
private fun processB(b: B): Int = 2
fun test(a: A) {
if (a is B) {
process<caret>B(a)
}
}
""".trimIndent()
)
val uCallExpression = myFixture.file.findElementAt(myFixture.caretOffset).toUElement().getUCallExpression()
.orFail("cant convert to UCallExpression")
val arg = uCallExpression.getArgumentForParameter(0)
TestCase.assertNotNull(arg)
TestCase.assertTrue(arg is USimpleNameReferenceExpression)
TestCase.assertEquals("a", (arg as? USimpleNameReferenceExpression)?.resolvedName)
}
fun checkDivByZero(myFixture: JavaCodeInsightTestFixture) { fun checkDivByZero(myFixture: JavaCodeInsightTestFixture) {
myFixture.configureByText( myFixture.configureByText(
"MyClass.kt", """ "MyClass.kt", """
......
...@@ -26,6 +26,10 @@ class FirUastApiFixtureTest : KotlinLightCodeInsightFixtureTestCase(), UastApiFi ...@@ -26,6 +26,10 @@ class FirUastApiFixtureTest : KotlinLightCodeInsightFixtureTestCase(), UastApiFi
doCheck("AssigningArrayElementType", ::checkAssigningArrayElementType) doCheck("AssigningArrayElementType", ::checkAssigningArrayElementType)
} }
fun testArgumentForParameter_smartcast() {
doCheck("ArgumentForParameter_smartcast", ::checkArgumentForParameter_smartcast)
}
fun testDivByZero() { fun testDivByZero() {
doCheck("DivByZero", ::checkDivByZero) doCheck("DivByZero", ::checkDivByZero)
} }
......
...@@ -19,6 +19,10 @@ class FE1UastApiFixtureTest : KotlinLightCodeInsightFixtureTestCase(), UastApiFi ...@@ -19,6 +19,10 @@ class FE1UastApiFixtureTest : KotlinLightCodeInsightFixtureTestCase(), UastApiFi
checkAssigningArrayElementType(myFixture) checkAssigningArrayElementType(myFixture)
} }
fun testArgumentForParameter_smartcast() {
checkArgumentForParameter_smartcast(myFixture)
}
fun testDivByZero() { fun testDivByZero() {
checkDivByZero(myFixture) checkDivByZero(myFixture)
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment