From 62ba73aae255daf5df3e10780ee4d8bb8419b419 Mon Sep 17 00:00:00 2001 From: "alexey.afanasiev" Date: Thu, 4 Oct 2018 12:11:51 +0300 Subject: [PATCH] [groovy] IDEA-198057 Fix substitutor calculation on explicit type arguments --- .../lang/resolve/MethodResolveResult.kt | 23 +++++++++---- .../resolve/processors/inference/inference.kt | 10 +++--- .../GrLatestHighlightingTest.groovy | 33 +++++++++++++++++++ 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/MethodResolveResult.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/MethodResolveResult.kt index 4e36d15a80b7..f966ee952c56 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/MethodResolveResult.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/MethodResolveResult.kt @@ -35,16 +35,25 @@ class MethodResolveResult( } private val applicabilitySubstitutor by lazy { - GroovyInferenceSessionBuilder(ref, methodCandidate).build().inferSubst() + if (ref.typeArguments.isNotEmpty()) { + methodCandidate.siteSubstitutor + } + else { + GroovyInferenceSessionBuilder(ref, methodCandidate).build().inferSubst() + } } private val fullSubstitutor by lazy { - GroovyInferenceSessionBuilder(ref, methodCandidate) - .addReturnConstraint() - .resolveMode(false) - .startFromTop(true) - .build() - .inferSubst(ref) + if (ref.typeArguments.isNotEmpty()) { + methodCandidate.siteSubstitutor + } + else { + GroovyInferenceSessionBuilder(ref, methodCandidate) + .addReturnConstraint() + .resolveMode(false) + .startFromTop(true) + .build().inferSubst(ref) + } } override fun getCandidate(): MethodCandidate? = methodCandidate diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/processors/inference/inference.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/processors/inference/inference.kt index 5f9a404074a9..7759d5a599fe 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/processors/inference/inference.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/processors/inference/inference.kt @@ -103,10 +103,8 @@ fun buildTopLevelArgumentTypes(place: PsiElement): Array { } fun PsiSubstitutor.putAll(parameters: Array, arguments: Array): PsiSubstitutor { - return this -// TODO deal with it -// if (arguments.size != parameters.size) return this -// return parameters.zip(arguments).fold(this) { acc, (param, arg) -> -// acc.put(param, arg) -// } + if (arguments.size != parameters.size) return this + return parameters.zip(arguments).fold(this) { acc, (param, arg) -> + acc.put(param, arg) + } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrLatestHighlightingTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrLatestHighlightingTest.groovy index 90cac24283aa..99c65d8f40cd 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrLatestHighlightingTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrLatestHighlightingTest.groovy @@ -524,6 +524,39 @@ class A { new A(foo: { prop }) +''' + } + + void 'test IDEA-198057-1'() { + testHighlighting ''' +Optional foo(Optional string) { + string.flatMap { + try { + return Optional.of(new BigDecimal(it)) + } catch (Exception ignored) { + return Optional. empty() + } + } +} +''' + } + + void 'test IDEA-198057-2'() { + testHighlighting ''' +Optional foo(Optional string) { + string.flatMap { + return Optional. empty() + } +} +''' + } + + void 'test IDEA-198057-3'() { + testHighlighting ''' +void foo() { + def o = Optional. empty() + Optional d = o +} ''' }