diff --git a/src/main/kotlin/de/sirywell/methodhandleplugin/inspection/MethodHandleCreationInspection.kt b/src/main/kotlin/de/sirywell/methodhandleplugin/inspection/MethodHandleCreationInspection.kt index eb0cbea..ab2d427 100644 --- a/src/main/kotlin/de/sirywell/methodhandleplugin/inspection/MethodHandleCreationInspection.kt +++ b/src/main/kotlin/de/sirywell/methodhandleplugin/inspection/MethodHandleCreationInspection.kt @@ -46,10 +46,13 @@ class MethodHandleCreationInspection: LocalInspectionTool() { type: MhExactType, parameter: PsiType ): Boolean { - if (type.signature.returnType is PsiPrimitiveType) { - return TypeConversionUtil.isAssignable(type.signature.returnType, parameter) + val returnType = type.signature.returnType + // void.class in invalid in constant(...), so skip here and handle it later separately + if (returnType == PsiType.VOID) return true + if (returnType is PsiPrimitiveType) { + return TypeConversionUtil.isAssignable(returnType, parameter) } - return TypeConversionUtil.areTypesConvertible(type.signature.returnType, parameter) + return TypeConversionUtil.areTypesConvertible(returnType, parameter) } private fun checkParamNotVoidAt(expression: PsiMethodCallExpression, index: Int) { diff --git a/src/test/kotlin/de/sirywell/methodhandleplugin/mhtype/MethodHandleInspectionsTest.kt b/src/test/kotlin/de/sirywell/methodhandleplugin/mhtype/MethodHandleInspectionsTest.kt index 2a2bf43..8098987 100644 --- a/src/test/kotlin/de/sirywell/methodhandleplugin/mhtype/MethodHandleInspectionsTest.kt +++ b/src/test/kotlin/de/sirywell/methodhandleplugin/mhtype/MethodHandleInspectionsTest.kt @@ -21,4 +21,6 @@ class MethodHandleInspectionsTest : LightJavaCodeInsightFixtureTestCase() { fun testWrongArgumentTypeInConstant() = doTest() + fun testVoidInConstant() = doTest() + } \ No newline at end of file diff --git a/src/test/testData/VoidInConstant.java b/src/test/testData/VoidInConstant.java new file mode 100644 index 0000000..9b7a5d0 --- /dev/null +++ b/src/test/testData/VoidInConstant.java @@ -0,0 +1,6 @@ +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; + +class VoidInIdentity { + private static final MethodHandle A = MethodHandles.constant(void.class, null); +} \ No newline at end of file