[groovy] treat void argument as null (IDEA-206425)

This commit is contained in:
Daniil Ovchinnikov
2019-01-31 17:56:34 +03:00
parent f7c3139b02
commit 04913fe696
3 changed files with 24 additions and 3 deletions
@@ -19,6 +19,7 @@ import org.jetbrains.plugins.groovy.lang.resolve.api.ExpressionArgument
import org.jetbrains.plugins.groovy.lang.resolve.api.JustTypeArgument
import org.jetbrains.plugins.groovy.lang.resolve.api.UnknownArgument
import org.jetbrains.plugins.groovy.lang.resolve.processors.ClassHint
import org.jetbrains.plugins.groovy.lang.typing.devoid
fun getTopLevelType(expression: GrExpression): PsiType? {
if (expression is GrMethodCall) {
@@ -27,7 +28,7 @@ fun getTopLevelType(expression: GrExpression): PsiType? {
val session = GroovyInferenceSessionBuilder(expression, it, resolved.contextSubstitutor)
.resolveMode(false)
.build()
return session.inferSubst().substitute(PsiUtil.getSmartReturnType(it.method))
return session.inferSubst().substitute(PsiUtil.getSmartReturnType(it.method).devoid(expression))
}
return null
}
@@ -1,4 +1,4 @@
// Copyright 2000-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 file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.groovy.lang.typing
import com.intellij.openapi.extensions.ExtensionPointName
@@ -70,7 +70,7 @@ private fun getTypeFromPropertyCall(element: PsiElement?, expression: GrMethodCa
return GrClosureSignatureUtil.getReturnType(type.signatures, argumentTypes, expression)
}
private fun PsiType?.devoid(context: PsiElement): PsiType? {
fun PsiType?.devoid(context: PsiElement): PsiType? {
return if (this == PsiType.VOID && !PsiUtil.isCompileStatic(context)) PsiType.NULL else this
}
@@ -0,0 +1,20 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.groovy.lang.resolve
import groovy.transform.CompileStatic
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyMethodResult
import org.jetbrains.plugins.groovy.lang.resolve.api.Applicability
import org.jetbrains.plugins.groovy.util.GroovyLatestTest
import org.jetbrains.plugins.groovy.util.ResolveTest
import org.junit.Test
@CompileStatic
class ResolveMethod2Test extends GroovyLatestTest implements ResolveTest {
@Test
void 'void argument'() {
def result = advancedResolveByText 'def foo(p); void bar(); <caret>foo(bar())'
assert result instanceof GroovyMethodResult
assert ((GroovyMethodResult)result).applicability == Applicability.applicable
}
}