Support contracts in PartialBodyResolveFilter
Previously, PartialBodyResolveFilter didn't know about contracts and was
filtering out calls of such functions, leading to unstable completion in
cases like that:
fun test(x: Any?) {
require(x is String)
x.<caret>
}
However, PartialBodyResolveFilter works by pure PSI, while to determine
if function has a contract we have to resolve it.
To solve it, we do something very similar to what has been done with
Nothin-returning functions: introduce
KotlinProbablyContractedFunctionShortNameIndex, which collects all
function which *may* have a contract during indexing.
^KT-25275 Fixed
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.resolve.lazy
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiRecursiveElementVisitor
|
||||
import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -38,6 +39,7 @@ class PartialBodyResolveFilter(
|
||||
private val statementMarks = StatementMarks()
|
||||
|
||||
private val globalProbablyNothingCallableNames = ProbablyNothingCallableNames.getInstance(declaration.project)
|
||||
private val globalProbablyContractedCallableNames = ProbablyContractedCallableNames.getInstance(declaration.project)
|
||||
|
||||
private val contextNothingFunctionNames = HashSet<String>()
|
||||
private val contextNothingVariableNames = HashSet<String>()
|
||||
@@ -169,6 +171,19 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitCallExpression(expression: KtCallExpression) {
|
||||
super.visitCallExpression(expression)
|
||||
|
||||
val nameReference = expression.calleeExpression as? KtNameReferenceExpression ?: return
|
||||
if (!globalProbablyContractedCallableNames.isProbablyContractedCallableName(nameReference.getReferencedName())) return
|
||||
|
||||
val mentionedSmartCastName = expression.findMentionedName(filter)
|
||||
|
||||
if (mentionedSmartCastName != null) {
|
||||
addPlace(mentionedSmartCastName, expression)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitBinaryWithTypeRHSExpression(expression: KtBinaryExpressionWithTypeRHS) {
|
||||
expression.acceptChildren(this)
|
||||
|
||||
@@ -259,6 +274,25 @@ class PartialBodyResolveFilter(
|
||||
return map
|
||||
}
|
||||
|
||||
private fun KtExpression.findMentionedName(filter: (SmartCastName) -> Boolean): SmartCastName? {
|
||||
var foundMentionedName: SmartCastName? = null
|
||||
|
||||
val visitor = object : PsiRecursiveElementVisitor() {
|
||||
override fun visitElement(element: PsiElement) {
|
||||
if (foundMentionedName != null) return
|
||||
|
||||
if (element !is KtSimpleNameExpression) super.visitElement(element)
|
||||
if (element !is KtExpression) return
|
||||
|
||||
element.smartCastExpressionName()?.takeIf(filter)?.let { foundMentionedName = it }
|
||||
}
|
||||
}
|
||||
|
||||
accept(visitor)
|
||||
|
||||
return foundMentionedName
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns names of expressions that would possibly be smart cast
|
||||
* in then (first component) and else (second component)
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.lazy
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.project.Project
|
||||
|
||||
interface ProbablyContractedCallableNames {
|
||||
fun isProbablyContractedCallableName(name: String): Boolean
|
||||
|
||||
companion object {
|
||||
fun getInstance(project: Project): ProbablyContractedCallableNames =
|
||||
ServiceManager.getService(project, ProbablyContractedCallableNames::class.java)!!
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.project
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.util.CachedValueProvider
|
||||
import com.intellij.psi.util.CachedValuesManager
|
||||
import com.intellij.psi.util.PsiModificationTracker
|
||||
import org.jetbrains.kotlin.idea.stubindex.KotlinProbablyContractedFunctionShortNameIndex
|
||||
import org.jetbrains.kotlin.resolve.lazy.ProbablyContractedCallableNames
|
||||
|
||||
class ProbablyContractedCallableNamesImpl(project: Project) : ProbablyContractedCallableNames {
|
||||
private val functionNames = CachedValuesManager.getManager(project).createCachedValue(
|
||||
{
|
||||
CachedValueProvider.Result.create(
|
||||
KotlinProbablyContractedFunctionShortNameIndex.getInstance().getAllKeys(project),
|
||||
PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT
|
||||
)
|
||||
},
|
||||
false
|
||||
)
|
||||
|
||||
override fun isProbablyContractedCallableName(name: String): Boolean = name in functionNames.value
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.stubindex
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.stubs.StringStubIndexExtension
|
||||
import com.intellij.psi.stubs.StubIndex
|
||||
import com.intellij.psi.stubs.StubIndexKey
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||
|
||||
class KotlinProbablyContractedFunctionShortNameIndex : StringStubIndexExtension<KtNamedFunction>() {
|
||||
override fun getKey(): StubIndexKey<String, KtNamedFunction> = KEY
|
||||
|
||||
override fun get(name: String, project: Project, scope: GlobalSearchScope): MutableCollection<KtNamedFunction> =
|
||||
StubIndex.getElements(KEY, name, project, scope, KtNamedFunction::class.java)
|
||||
|
||||
companion object {
|
||||
private val KEY: StubIndexKey<String, KtNamedFunction> =
|
||||
KotlinIndexUtil.createIndexKey(KotlinProbablyContractedFunctionShortNameIndex::class.java)
|
||||
|
||||
private val ourInstance = KotlinProbablyContractedFunctionShortNameIndex()
|
||||
|
||||
@JvmStatic
|
||||
fun getInstance(): KotlinProbablyContractedFunctionShortNameIndex = ourInstance
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+ReadDeserializedContracts -XXLanguage:+UseReturnsEffect
|
||||
|
||||
interface Foo {
|
||||
val x: Int
|
||||
|
||||
fun f()
|
||||
}
|
||||
|
||||
fun test(x: Any?) {
|
||||
require(x is Foo)
|
||||
x.<caret>
|
||||
}
|
||||
|
||||
// EXIST: x
|
||||
// EXIST: f
|
||||
+5
@@ -2218,6 +2218,11 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/basic/common/smartCast"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("functionWithContract.kt")
|
||||
public void testFunctionWithContract() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/smartCast/functionWithContract.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("MemberExtensionAfterThisSmartCast.kt")
|
||||
public void testMemberExtensionAfterThisSmartCast() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/smartCast/MemberExtensionAfterThisSmartCast.kt");
|
||||
|
||||
+5
@@ -2218,6 +2218,11 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/basic/common/smartCast"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("functionWithContract.kt")
|
||||
public void testFunctionWithContract() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/smartCast/functionWithContract.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("MemberExtensionAfterThisSmartCast.kt")
|
||||
public void testMemberExtensionAfterThisSmartCast() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/smartCast/MemberExtensionAfterThisSmartCast.kt");
|
||||
|
||||
@@ -354,6 +354,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.resolve.lazy.ProbablyNothingCallableNames"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.project.ProbablyNothingCallableNamesImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.resolve.lazy.ProbablyContractedCallableNames"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.project.ProbablyContractedCallableNamesImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings"/>
|
||||
|
||||
@@ -701,6 +704,7 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinAnnotationsIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyNothingFunctionShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyNothingPropertyShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyContractedFunctionShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFileFacadeFqNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFilePartClassIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFileFacadeClassByPackageIndex"/>
|
||||
|
||||
@@ -354,6 +354,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.resolve.lazy.ProbablyNothingCallableNames"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.project.ProbablyNothingCallableNamesImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.resolve.lazy.ProbablyContractedCallableNames"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.project.ProbablyContractedCallableNamesImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings"/>
|
||||
|
||||
@@ -698,6 +701,7 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinAnnotationsIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyNothingFunctionShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyNothingPropertyShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyContractedFunctionShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFileFacadeFqNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFilePartClassIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFileFacadeClassByPackageIndex"/>
|
||||
|
||||
@@ -354,6 +354,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.resolve.lazy.ProbablyNothingCallableNames"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.project.ProbablyNothingCallableNamesImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.resolve.lazy.ProbablyContractedCallableNames"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.project.ProbablyContractedCallableNamesImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings"/>
|
||||
|
||||
@@ -701,6 +704,7 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinAnnotationsIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyNothingFunctionShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyNothingPropertyShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyContractedFunctionShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFileFacadeFqNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFilePartClassIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFileFacadeClassByPackageIndex"/>
|
||||
|
||||
@@ -355,6 +355,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.resolve.lazy.ProbablyNothingCallableNames"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.project.ProbablyNothingCallableNamesImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.resolve.lazy.ProbablyContractedCallableNames"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.project.ProbablyContractedCallableNamesImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings"/>
|
||||
|
||||
@@ -702,6 +705,7 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinAnnotationsIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyNothingFunctionShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyNothingPropertyShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyContractedFunctionShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFileFacadeFqNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFilePartClassIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFileFacadeClassByPackageIndex"/>
|
||||
|
||||
@@ -354,6 +354,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.resolve.lazy.ProbablyNothingCallableNames"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.project.ProbablyNothingCallableNamesImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.resolve.lazy.ProbablyContractedCallableNames"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.project.ProbablyContractedCallableNamesImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings"/>
|
||||
|
||||
@@ -701,6 +704,7 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinAnnotationsIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyNothingFunctionShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyNothingPropertyShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyContractedFunctionShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFileFacadeFqNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFilePartClassIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFileFacadeClassByPackageIndex"/>
|
||||
|
||||
@@ -354,6 +354,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.resolve.lazy.ProbablyNothingCallableNames"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.project.ProbablyNothingCallableNamesImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.resolve.lazy.ProbablyContractedCallableNames"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.project.ProbablyContractedCallableNamesImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings"/>
|
||||
|
||||
@@ -701,6 +704,7 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinAnnotationsIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyNothingFunctionShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyNothingPropertyShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyContractedFunctionShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFileFacadeFqNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFilePartClassIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFileFacadeClassByPackageIndex"/>
|
||||
|
||||
@@ -353,6 +353,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.resolve.lazy.ProbablyNothingCallableNames"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.project.ProbablyNothingCallableNamesImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.resolve.lazy.ProbablyContractedCallableNames"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.project.ProbablyContractedCallableNamesImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings"/>
|
||||
|
||||
@@ -700,6 +703,7 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinAnnotationsIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyNothingFunctionShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyNothingPropertyShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyContractedFunctionShortNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFileFacadeFqNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFilePartClassIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinFileFacadeClassByPackageIndex"/>
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
Resolve target: value-parameter x: kotlin.Any? smart-cast to kotlin.String
|
||||
----------------------------------------------
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+ReadDeserializedContracts -XXLanguage:+UseReturnsEffect
|
||||
package test
|
||||
|
||||
fun irrelevantConsume(y: Any?) {}
|
||||
|
||||
fun testContractFromBinaryDependency(x: Any?, y: Any?) {
|
||||
require(x is String)
|
||||
|
||||
require(y is String)
|
||||
/* STATEMENT DELETED: irrelevantConsume(x) */
|
||||
|
||||
<caret>x.length
|
||||
|
||||
/* STATEMENT DELETED: require(x is Int) */
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
Resolve target: value-parameter x: kotlin.Any? smart-cast to kotlin.String
|
||||
----------------------------------------------
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+ReadDeserializedContracts -XXLanguage:+UseReturnsEffect
|
||||
package test
|
||||
|
||||
fun irrelevantConsume(y: Any?) {}
|
||||
|
||||
fun testContractFromBinaryDependency(x: Any?, y: Any?) {
|
||||
require(x is String)
|
||||
|
||||
/* STATEMENT DELETED: require(y is String) */
|
||||
/* STATEMENT DELETED: irrelevantConsume(x) */
|
||||
|
||||
<caret>x.length
|
||||
|
||||
/* STATEMENT DELETED: require(x is Int) */
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+ReadDeserializedContracts -XXLanguage:+UseReturnsEffect
|
||||
package test
|
||||
|
||||
fun irrelevantConsume(y: Any?) {}
|
||||
|
||||
fun testContractFromBinaryDependency(x: Any?, y: Any?) {
|
||||
require(x is String)
|
||||
|
||||
require(y is String)
|
||||
irrelevantConsume(x)
|
||||
|
||||
<caret>x.length
|
||||
|
||||
require(x is Int)
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
Resolve target: value-parameter x: kotlin.Any? smart-cast to kotlin.String
|
||||
----------------------------------------------
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+AllowContractsForCustomFunctions -XXLanguage:+UseReturnsEffect
|
||||
@file:Suppress("INVISIBLE_MEMBER")
|
||||
package test
|
||||
|
||||
import kotlin.internal.contracts.*
|
||||
|
||||
fun myRequire(x: Boolean) {
|
||||
contract {
|
||||
returns() implies x
|
||||
}
|
||||
}
|
||||
|
||||
fun testContractFromSource(x: Any?, y: Any?) {
|
||||
myRequire(x is String)
|
||||
myRequire(y is String)
|
||||
|
||||
<caret>x.length
|
||||
|
||||
/* STATEMENT DELETED: myRequire(x is Int) */
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
Resolve target: value-parameter x: kotlin.Any? smart-cast to kotlin.String
|
||||
----------------------------------------------
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+AllowContractsForCustomFunctions -XXLanguage:+UseReturnsEffect
|
||||
@file:Suppress("INVISIBLE_MEMBER")
|
||||
package test
|
||||
|
||||
import kotlin.internal.contracts.*
|
||||
|
||||
fun myRequire(x: Boolean) {
|
||||
contract {
|
||||
returns() implies x
|
||||
}
|
||||
}
|
||||
|
||||
fun testContractFromSource(x: Any?, y: Any?) {
|
||||
myRequire(x is String)
|
||||
/* STATEMENT DELETED: myRequire(y is String) */
|
||||
|
||||
<caret>x.length
|
||||
|
||||
/* STATEMENT DELETED: myRequire(x is Int) */
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+AllowContractsForCustomFunctions -XXLanguage:+UseReturnsEffect
|
||||
@file:Suppress("INVISIBLE_MEMBER")
|
||||
package test
|
||||
|
||||
import kotlin.internal.contracts.*
|
||||
|
||||
fun myRequire(x: Boolean) {
|
||||
contract {
|
||||
returns() implies x
|
||||
}
|
||||
}
|
||||
|
||||
fun testContractFromSource(x: Any?, y: Any?) {
|
||||
myRequire(x is String)
|
||||
myRequire(y is String)
|
||||
|
||||
<caret>x.length
|
||||
|
||||
myRequire(x is Int)
|
||||
}
|
||||
@@ -9,7 +9,10 @@ fun foo(p: Int) {
|
||||
val v2 = v1 * v1
|
||||
val v3 = v1 * v2
|
||||
|
||||
/* STATEMENT DELETED: run { val v2 = 1 println(v2) } */
|
||||
run {
|
||||
val v2 = 1
|
||||
println(v2)
|
||||
}
|
||||
|
||||
print(<caret>v2)
|
||||
|
||||
|
||||
@@ -9,7 +9,10 @@ fun foo(p: Int) {
|
||||
val v2 = v1 * v1
|
||||
/* STATEMENT DELETED: val v3 = v1 * v2 */
|
||||
|
||||
/* STATEMENT DELETED: run { val v2 = 1 println(v2) } */
|
||||
run {
|
||||
val v2 = 1
|
||||
println(v2)
|
||||
}
|
||||
|
||||
print(<caret>v2)
|
||||
|
||||
|
||||
+10
@@ -59,6 +59,16 @@ public class PartialBodyResolveTestGenerated extends AbstractPartialBodyResolveT
|
||||
runTest("idea/testData/resolve/partialBodyResolve/ClassInitializerHasNoValue.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ContractFromBinary.kt")
|
||||
public void testContractFromBinary() throws Exception {
|
||||
runTest("idea/testData/resolve/partialBodyResolve/ContractFromBinary.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ContractFromSource.kt")
|
||||
public void testContractFromSource() throws Exception {
|
||||
runTest("idea/testData/resolve/partialBodyResolve/ContractFromSource.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("DeclarationsBefore.kt")
|
||||
public void testDeclarationsBefore() throws Exception {
|
||||
runTest("idea/testData/resolve/partialBodyResolve/DeclarationsBefore.kt");
|
||||
|
||||
Reference in New Issue
Block a user