From c075d27731ffa4d0f6af9fe2caf2a521e5a58233 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Thu, 23 Jun 2016 15:24:45 +0300 Subject: [PATCH] Change Signature: Consider default value context an initial type context. Use parameter list as a type context for bodyless function #KT-12413 Fixed (cherry picked from commit f417b05) --- ChangeLog.md | 6 ++++++ .../idea/caches/resolve/CodeFragmentAnalyzer.kt | 14 +++++++------- .../ui/KotlinChangeSignatureDialog.kt | 5 +++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 82d26fabf4a..89f7307a960 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -113,6 +113,12 @@ These artifacts include extensions for the types available in the latter JDKs, s - [`KT-13037`](https://youtrack.jetbrains.com/issue/KT-13037) Fix possible deadlock in debugger in 2016.1 and exception in 2016.2 - [`KT-12651`](https://youtrack.jetbrains.com/issue/KT-12651) Fix exception in evaluate expression when bad identifier is used for marking object +#### Refactorings + +###### Issues fixed + +- [`KT-12413`](https://youtrack.jetbrains.com/issue/KT-12413) Change Signature: Fix bogus warning about unresolved type parameters/invalid functional type replacement + ## 1.0.3 ### Compiler diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/CodeFragmentAnalyzer.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/CodeFragmentAnalyzer.kt index f53fcc24b1f..4739dc288af 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/CodeFragmentAnalyzer.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/CodeFragmentAnalyzer.kt @@ -72,7 +72,7 @@ class CodeFragmentAnalyzer( } //TODO: this code should be moved into debugger which should set correct context for its code fragment - private fun KtExpression.correctContextForExpression(): KtExpression { + private fun KtElement.correctContextForElement(): KtElement { return when (this) { is KtProperty -> this.delegateExpressionOrInitializer is KtFunctionLiteral -> this.bodyExpression?.statements?.lastOrNull() @@ -112,18 +112,18 @@ class CodeFragmentAnalyzer( scopeForContextElement = descriptor.scopeForMemberDeclarationResolution dataFlowInfo = DataFlowInfo.EMPTY } - is KtExpression -> { - val correctedContext = context.correctContextForExpression() + is KtFile -> { + scopeForContextElement = resolveSession.fileScopeProvider.getFileResolutionScope(context) + dataFlowInfo = DataFlowInfo.EMPTY + } + is KtElement -> { + val correctedContext = context.correctContextForElement() val contextForElement = resolveToElement(correctedContext) scopeForContextElement = contextForElement[BindingContext.LEXICAL_SCOPE, correctedContext] dataFlowInfo = contextForElement.getDataFlowInfo(correctedContext) } - is KtFile -> { - scopeForContextElement = resolveSession.fileScopeProvider.getFileResolutionScope(context) - dataFlowInfo = DataFlowInfo.EMPTY - } else -> return null } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/KotlinChangeSignatureDialog.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/KotlinChangeSignatureDialog.kt index 0d96d3b728a..9594d5c93fe 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/KotlinChangeSignatureDialog.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/KotlinChangeSignatureDialog.kt @@ -54,6 +54,7 @@ import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinMethodDescrip import org.jetbrains.kotlin.idea.refactoring.validateElement import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.parents +import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import java.awt.BorderLayout @@ -407,9 +408,9 @@ class KotlinChangeSignatureDialog( } private fun getTypeCodeFragmentContext(startFrom: PsiElement): KtElement { - return startFrom.parents.mapNotNull { + return startFrom.parentsWithSelf.mapNotNull { when { - it is KtNamedFunction -> it.bodyExpression + it is KtNamedFunction -> it.bodyExpression ?: it.valueParameterList it is KtPropertyAccessor -> it.bodyExpression it is KtDeclaration && KtPsiUtil.isLocal(it) -> null it is KtConstructor<*> -> it