Skip to content

Commit 0d51a2e

Browse files
committed
Optimize for void return type for functions with no return type
+ small refacroring
1 parent 9e90459 commit 0d51a2e

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightMembersCreator.kt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,7 @@ internal class UltraLightMembersCreator(
171171
val returnType: PsiType? by lazyPub {
172172
when {
173173
isConstructor -> null
174-
isSuspendFunction -> support.moduleDescriptor
175-
.builtIns
176-
.nullableAnyType
177-
.asPsiType(support, TypeMappingMode.DEFAULT, wrapper)
178-
else -> methodReturnType(ktFunction, wrapper)
174+
else -> methodReturnType(ktFunction, wrapper, isSuspendFunction)
179175
}
180176
}
181177

@@ -188,7 +184,20 @@ internal class UltraLightMembersCreator(
188184
method.delegate.addParameter(KtUltraLightReceiverParameter(callable, support, method))
189185
}
190186

191-
private fun methodReturnType(ktDeclaration: KtDeclaration, wrapper: KtUltraLightMethod): PsiType {
187+
private fun methodReturnType(ktDeclaration: KtDeclaration, wrapper: KtUltraLightMethod, isSuspendFunction: Boolean): PsiType {
188+
189+
if (isSuspendFunction) {
190+
return support.moduleDescriptor
191+
.builtIns
192+
.nullableAnyType
193+
.asPsiType(support, TypeMappingMode.DEFAULT, wrapper)
194+
}
195+
196+
if (ktDeclaration is KtNamedFunction &&
197+
ktDeclaration.hasBlockBody() &&
198+
!ktDeclaration.hasDeclaredReturnType()
199+
) return PsiType.VOID
200+
192201
val desc =
193202
ktDeclaration.resolve()?.getterIfProperty() as? FunctionDescriptor
194203
?: return PsiType.NULL
@@ -359,7 +368,7 @@ internal class UltraLightMembersCreator(
359368
val getterName = computeMethodName(ktGetter ?: declaration, JvmAbi.getterName(propertyName), MethodType.GETTER)
360369
val getterPrototype = lightMethod(getterName, ktGetter ?: declaration, onlyJvmStatic || forceStatic)
361370
val getterWrapper = KtUltraLightMethodForSourceDeclaration(getterPrototype, declaration, support, containingClass)
362-
val getterType: PsiType by lazyPub { methodReturnType(declaration, getterWrapper) }
371+
val getterType: PsiType by lazyPub { methodReturnType(declaration, getterWrapper, isSuspendFunction = false) }
363372
getterPrototype.setMethodReturnType { getterType }
364373
addReceiverParameter(declaration, getterWrapper)
365374
result.add(getterWrapper)

0 commit comments

Comments
 (0)