Skip to content

Commit

Permalink
Fix #2260 expects varargs as return value for varargs target
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNesto committed Jul 5, 2024
1 parent 838067d commit 8f06f60
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.demonwav.mcdev.platform.mixin.util.isConstructor
import com.demonwav.mcdev.platform.mixin.util.isMixinExtrasSugar
import com.demonwav.mcdev.util.Parameter
import com.demonwav.mcdev.util.fullQualifiedName
import com.demonwav.mcdev.util.normalize
import com.demonwav.mcdev.util.synchronize
import com.intellij.codeInsight.intention.FileModifier.SafeFieldForPreview
import com.intellij.codeInsight.intention.QuickFixFactory
Expand All @@ -46,6 +47,7 @@ import com.intellij.psi.JavaElementVisitor
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiClassType
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.PsiEllipsisType
import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiModifier
import com.intellij.psi.PsiNameHelper
Expand All @@ -55,7 +57,6 @@ import com.intellij.psi.PsiType
import com.intellij.psi.codeStyle.JavaCodeStyleManager
import com.intellij.psi.codeStyle.VariableKind
import com.intellij.psi.util.PsiUtil
import com.intellij.psi.util.TypeConversionUtil
import org.objectweb.asm.Opcodes

class InvalidInjectorMethodSignatureInspection : MixinInspection() {
Expand Down Expand Up @@ -195,13 +196,18 @@ class InvalidInjectorMethodSignatureInspection : MixinInspection() {
) {
reportedSignature = true

val normalizedExpected = when (expectedReturnType) {
is PsiEllipsisType -> expectedReturnType.toArrayType()
else -> expectedReturnType
}

holder.registerProblem(
method.returnTypeElement ?: identifier,
"Expected return type '${expectedReturnType.presentableText}' " +
"Expected return type '${normalizedExpected.presentableText}' " +
"for $annotationName method",
QuickFixFactory.getInstance().createMethodReturnFix(
method,
expectedReturnType,
normalizedExpected,
false,
),
)
Expand All @@ -218,9 +224,9 @@ class InvalidInjectorMethodSignatureInspection : MixinInspection() {
method: PsiMethod,
allowCoerce: Boolean,
): Boolean {
val expectedErasure = TypeConversionUtil.erasure(expectedReturnType)
val returnErasure = TypeConversionUtil.erasure(methodReturnType)
if (expectedErasure == returnErasure) {
val normalizedExpected = expectedReturnType.normalize()
val normalizedReturn = methodReturnType.normalize()
if (normalizedExpected == normalizedReturn) {
return true
}
if (!allowCoerce || !method.hasAnnotation(COERCE)) {
Expand Down

0 comments on commit 8f06f60

Please sign in to comment.