Skip to content

Commit 0a7af7c

Browse files
committed
Add error for when an enum mixin targets a non-enum class
1 parent c54831e commit 0a7af7c

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/main/kotlin/platform/mixin/inspection/MixinClassTypeInspection.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class MixinClassTypeInspection : MixinInspection() {
5959

6060
val needsToBeClass = mixinClass.mixinTargets.any { !it.hasAccess(Opcodes.ACC_INTERFACE) }
6161
val needsToBeInterface = mixinClass.mixinTargets.any { it.hasAccess(Opcodes.ACC_INTERFACE) }
62+
val canBeEnum = mixinClass.mixinTargets.all { it.hasAccess(Opcodes.ACC_ENUM) }
6263

6364
val fixes = mutableListOf<LocalQuickFix>()
6465
if (classKeywordElement != null) {
@@ -67,11 +68,20 @@ class MixinClassTypeInspection : MixinInspection() {
6768
} else if (needsToBeInterface && !needsToBeClass) {
6869
fixes += ChangeClassTypeFix(classKeywordElement, JavaKeywords.INTERFACE)
6970
}
71+
if (canBeEnum) {
72+
fixes += ChangeClassTypeFix(classKeywordElement, JavaKeywords.ENUM)
73+
}
7074
}
7175

72-
if (mixinClass.isEnum && !mixinClass.isFabricMixin) {
73-
holder.registerProblem(problemElement, "Mixins cannot be enums", *fixes.toTypedArray())
74-
return
76+
if (mixinClass.isEnum) {
77+
if (!mixinClass.isFabricMixin) {
78+
holder.registerProblem(problemElement, "Enum Mixins are not supported on this platform", *fixes.toTypedArray())
79+
return
80+
}
81+
if (!canBeEnum) {
82+
holder.registerProblem(problemElement, "Enum Mixin targets a non-enum class", *fixes.toTypedArray())
83+
return
84+
}
7585
}
7686

7787
if (mixinClass.isAnnotationType) {

0 commit comments

Comments
 (0)