Fix error in kapt on enum constructors with parameters
Do not skip writing the fictitious 'java/lang/Synthetic' annotation in KAPT mode, because its absence makes ASM confuse indices of enum constructor parameters (it cannot figure out that there are two additional parameters, name and ordinal) #KT-12694 Fixed
This commit is contained in:
@@ -294,7 +294,7 @@ public class FunctionCodegen {
|
||||
|
||||
private void markEnumOrInnerConstructorParameterAsSynthetic(MethodVisitor mv, int i) {
|
||||
// IDEA's ClsPsi builder fails to annotate synthetic parameters
|
||||
if (state.getClassBuilderMode() != ClassBuilderMode.FULL) return;
|
||||
if (state.getClassBuilderMode() == ClassBuilderMode.LIGHT_CLASSES) return;
|
||||
|
||||
// This is needed to avoid RuntimeInvisibleParameterAnnotations error in javac:
|
||||
// see MethodWriter.visitParameterAnnotation()
|
||||
|
||||
+16
@@ -36,6 +36,22 @@ class KaptIT: BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEnumConstructor() {
|
||||
val project = Project("kaptEnumConstructor", GRADLE_VERSION)
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
assertContains(":compileKotlin")
|
||||
assertContains(":compileJava")
|
||||
assertFileExists("build/tmp/kapt/main/wrappers/annotations.main.txt")
|
||||
}
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStubs() {
|
||||
val project = Project("kaptStubs", GRADLE_VERSION)
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.1-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
maven { url 'file://' + pathToKotlinPlugin }
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: "java"
|
||||
apply plugin: "kotlin"
|
||||
|
||||
repositories {
|
||||
maven { url 'file://' + pathToKotlinPlugin }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
compile "org.jetbrains.kotlin:annotation-processor-example:$kotlin_version"
|
||||
kapt "org.jetbrains.kotlin:annotation-processor-example:$kotlin_version"
|
||||
}
|
||||
|
||||
kapt {
|
||||
generateStubs = true
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package javaPackage;
|
||||
|
||||
import example.TestEnum;
|
||||
|
||||
public class JavaClass {
|
||||
public void test() {
|
||||
TestEnum t = TestEnum.ENTRY;
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// See KT-12694 Java class cannot access (Kotlin) enum with String constructor param
|
||||
|
||||
package example
|
||||
|
||||
enum class TestEnum(val value: String) {
|
||||
ENTRY("");
|
||||
}
|
||||
Reference in New Issue
Block a user