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 1fa5a4f22d8e..244559760a86 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 @@ -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 } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/typing/DefaultMethodCallTypeCalculator.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/typing/DefaultMethodCallTypeCalculator.kt index a36f5be5920f..2e37f64f50f0 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/typing/DefaultMethodCallTypeCalculator.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/typing/DefaultMethodCallTypeCalculator.kt @@ -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 } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethod2Test.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethod2Test.groovy new file mode 100644 index 000000000000..f8db19b41401 --- /dev/null +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethod2Test.groovy @@ -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(); foo(bar())' + assert result instanceof GroovyMethodResult + assert ((GroovyMethodResult)result).applicability == Applicability.applicable + } +}