[groovy] IDEA-198057 Fix substitutor calculation on explicit type arguments

This commit is contained in:
alexey.afanasiev
2018-10-04 12:12:24 +03:00
parent c40f0e4dd5
commit 62ba73aae2
3 changed files with 53 additions and 13 deletions
@@ -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
@@ -103,10 +103,8 @@ fun buildTopLevelArgumentTypes(place: PsiElement): Array<PsiType?> {
}
fun PsiSubstitutor.putAll(parameters: Array<out PsiTypeParameter>, arguments: Array<out PsiType>): 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)
}
}
@@ -524,6 +524,39 @@ class A {
new A(foo: {
prop
})
'''
}
void 'test IDEA-198057-1'() {
testHighlighting '''
Optional<BigDecimal> foo(Optional<String> string) {
string.flatMap {
try {
return Optional.of(new BigDecimal(it))
} catch (Exception ignored) {
return Optional.<BigDecimal> empty()
}
}
}
'''
}
void 'test IDEA-198057-2'() {
testHighlighting '''
Optional<BigDecimal> foo(Optional<String> string) {
string.flatMap {
return Optional.<BigDecimal> empty()
}
}
'''
}
void 'test IDEA-198057-3'() {
testHighlighting '''
void foo() {
def o = Optional.<BigDecimal> empty()
Optional<BigDecimal> d = o
}
'''
}